text changed on another form
-
hi, i have two forms and i m changing text of a control on second form from first form through a static property.now i show the second form but the text doesnt changes.wat is wrong?
-
hi, i have two forms and i m changing text of a control on second form from first form through a static property.now i show the second form but the text doesnt changes.wat is wrong?
Can you show your code? Its difficult to tell what is wrong without seeing your code.
-
hi, i have two forms and i m changing text of a control on second form from first form through a static property.now i show the second form but the text doesnt changes.wat is wrong?
-
hi, i have two forms and i m changing text of a control on second form from first form through a static property.now i show the second form but the text doesnt changes.wat is wrong?
There could be so many things wrong, it is impossible to be definite. However, the first question for you is: why are you using a static property? You do realise that it is shared by all instances of the form? Try using a public property on Form2, and use it in the form load event:
public string myText { get; set; }
...
private void Form2_Load(object sender, EventArgs e)
{
label1.Text = myText;
}Then in Form1:
Form2 myForm = new Form2();
myForm.myText = "Hello World!";
myForm.Show();If this doesn't solve your problem, then you will have to post relevent code fragments from Form1 and Form2 (enclosing in <pre>...</pre> blocks with the "code block" widget to preserve the formatting and make it easier to read) - don't just post your entire project, nobody wants to wade through loads of irrelevant code!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
-
There could be so many things wrong, it is impossible to be definite. However, the first question for you is: why are you using a static property? You do realise that it is shared by all instances of the form? Try using a public property on Form2, and use it in the form load event:
public string myText { get; set; }
...
private void Form2_Load(object sender, EventArgs e)
{
label1.Text = myText;
}Then in Form1:
Form2 myForm = new Form2();
myForm.myText = "Hello World!";
myForm.Show();If this doesn't solve your problem, then you will have to post relevent code fragments from Form1 and Form2 (enclosing in <pre>...</pre> blocks with the "code block" widget to preserve the formatting and make it easier to read) - don't just post your entire project, nobody wants to wade through loads of irrelevant code!
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
thanx all problem solved...
-
thanx all problem solved...
actually the form2 was getting disposed before setting its control's text...
-
hi, i have two forms and i m changing text of a control on second form from first form through a static property.now i show the second form but the text doesnt changes.wat is wrong?
you can use delegation to solve your problem
EASY COME EASY GO
-
actually the form2 was getting disposed before setting its control's text...
Oops. :doh:
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy