I have two forms. Let say, form1 and form2. in form1 class, i have method ChangeColor() and i am calling this method in button click event of form2. But it is not changing the color of form2.
Please find the below code:
Below code is for form1, where on click of Button1, form2 is opening.
Expand|Select|Wrap|Line Numbers
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Form2 fm2 = new Form2();
- fm2.Show();
- }
- public void changecolor()
- {
- this.BackColor = Color.Red;
- this.Refresh();
- }
- }
Expand|Select|Wrap|Line Numbers
- public partial class Form2 : Form
- {
- public Form2()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Form1 frm1=new Form1();
- frm1.changecolor();
- }
- }
Thanks,
Snehasis