I created 2 two classes: Form1 and Form2 under the same namespace.
+ Form1.cs was a dialog.
+ Form2.cs was just a normal class.
In Form1 I created a button, with the public variable, named button1.
In Form2 I wrote a method :
public void ChangeBackColor()
{
Form1 obj = new Form1();
obj.button1.BackColor = Color.Blue;
MessageBox.Show(obj.button1.BackColor.ToString());
}
Then in Form1 I also wrote a method to call the ChangeBackColor() from Form2 :
public void Click()
{
Form2 obj_f2 = new Form2();
obj_f2.ChangeBackColor();
}
The compiling process generated 0 errors and the program still ran.
But when I click a button to call Click() from Form1
It just appeared a Message Box showing the Default Color of button1
the Color did not change.
Anybody can help me ??
That seemed simple but I still can not find the reason WHY ?
+ Form1.cs was a dialog.
+ Form2.cs was just a normal class.
In Form1 I created a button, with the public variable, named button1.
In Form2 I wrote a method :
public void ChangeBackColor()
{
Form1 obj = new Form1();
obj.button1.BackColor = Color.Blue;
MessageBox.Show(obj.button1.BackColor.ToString());
}
Then in Form1 I also wrote a method to call the ChangeBackColor() from Form2 :
public void Click()
{
Form2 obj_f2 = new Form2();
obj_f2.ChangeBackColor();
}
The compiling process generated 0 errors and the program still ran.
But when I click a button to call Click() from Form1
It just appeared a Message Box showing the Default Color of button1
the Color did not change.
Anybody can help me ??
That seemed simple but I still can not find the reason WHY ?