c# - How to enable button in Form 1 from Form 2 using public get set? -


i have 2 buttons in form 1, 1 "showform2" button , 1 "button1" button.

button 1 disable default. , when click "showform2" button, form 2 show.

prntscn of form 1

so, want is, when click "button2" in form 2, enable "button1" in form 1.

enter image description here

so, try code in form2 class:

public partial class form2 : form {     bool enable_form1_button1;     public bool enable_form1_button1     {         { return this.enable_form1_button1; }         set { this.enable_form1_button1 = value; }     }     public form2()     {         initializecomponent();     }      private void button2_click(object sender, eventargs e)     {         enable_form1_button1 = true;     } } 

then in form1 class, expecting "enable_form1_button1 = true" pass form 1 , enable form 1 button1. how this?

public partial class form1 : form {     public form1()     {         initializecomponent();     }      private void btb_showfrm2_click(object sender, eventargs e)     {         form2 frm2 = new form2();         frm2.show();         button1.enabled = frm2.enable_form1_button1; // put here, , not seems right     } } 

form1.cs

    public partial class form1 : form     {     public form1()     {         initializecomponent();         button1.enabled = false;     }      private void button2_click(object sender, eventargs e)     {         form2 ofrm2 = new form2();         ofrm2.evtfrm += new showfrm(ofrm2_evtfrm);         ofrm2.show();     }      void ofrm2_evtfrm()     {         button1.enabled = true;     } } 

form2.cs

    public delegate void showfrm();     public partial class form2 : form     {     public event showfrm evtfrm;     public form2()     {         initializecomponent();     }      private void button1_click(object sender, eventargs e)     {         if (evtfrm != null)         {             evtfrm();         }     } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -