c# - Duplicate parent forms as a result of calling a function from a child form -


in application have parent form , popup form. in popup form when click on button1, application supposed call function , result of function, label has change text. although popup button works, have 2 parent forms; 1 label in default state , 1 label changed result of clicking on button in popup. there way me hide initial parent form? here code i'm using in popup form:

 public form1 f1 = new form1();  private void button1_click(object sender, eventargs e)     {          f1.referansyaz = true;         f1.show();      } 

so when change variable "referansyaz" true, call function in form 1 , result of function label in form 1 (or parent form) changes. , f1.show(), opens updated form 1.

you can change code , pass method changes label on parent form delegate second form. i'd recommend not pass instance of parent form child form because breaks open-closed principle...

so in main form type:

public partial class form1 : form  {    public action<bool> a;  `         public form1()    {       initializecomponent();       = new action<bool>(newvalue => this.referansyaz.text = newvalue.tostring());    }    // code create form2     form2 newform = new form2(a); } 

then in second form :

public partial class form2 : form {    action<bool> a;      public form2(action<bool> a)    {       this.a = a;    }     private void button1_click(object sender, eventargs e)    {             a(true);    } } 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -