Actually the way of accessing values that you are using is not appreciated...
you're declaring a static member of your the form.......your form becomes dependent on each other and needs to be changed if included in different projects...
it cuts out the flexibility of your application to be used in several projects..
And doesn't really follow the Resuability concept of object oriented programming...
But i've got a better a better way to do it....
Using your examples....here's what i got for you....
There are 2 forms Form1 and Form2...
lblMax is in Form1
txtMax is in Form2
Form1 acts as the Main UI or main Form
Form2 acts as a dialog where settings need to be done so that it could reflect in Form1....
So what you would do here is put up a lauch button you can call it as settings
to open Form2...and when data is enetered in Form2 and Form2 is closed the data in lblMax in Form1 will get updated to whatever is entered in txtMax in Form2....
code of Form1
this code should be written at button click event
-
private void Button1_Click(object sender,EventArgs E)
-
{
-
Form2 frm2 =new Form2()'
-
frm2.ShowDialog(); // show Form2
-
lblMax.Text=frm2.MaxValue; //getting the value of txtMax via a Form2 property after the Form2 gets closed...
-
}
-
code of Form2
this should be wriiten at OK button click event
-
private void btnOK_Click(object sender,EventArgs E)
-
{
-
_maxVal=txtMax.Text;
-
}
-
this code should be declared as a class property in Form2
-
private string _maxVal="";
-
public string MaxValue
-
{
-
get{return _maxVal;}
-
}
-
Now that's the most correct solution.....you'd ever find....and show it to those personnel who recommended you to code like that....
Why did i explained you these because...accessing values to memebers like that is not a good practice....and if you go on programming like that ...you'll land up in trouble wh en youre into an industry....
And if you want some help about good programming issues you can download my ebook which is written by me of course...which is exclusively for students...
here is the link...
http://thatthatsite.yolasite.com/
Reply me if this book was useful....