C# forms and textboxes -


how access textbox in form1 when click button form2?

i want write specific text in textbox in form1 after click button form2 , closes itself.

as guessed can solve issue as

form1.cs

public partial class form1 : form {     public form1()     {         initializecomponent();     }     private void button1_click(object sender, eventargs e)     {         launchform2();     }     private void launchform2()     {         using (var form2 = new form2())         {             form2.ontextenteredhandler += form2_ontextenteredhandler;             form2.showdialog();         }     }      private void form2_ontextenteredhandler(string text)     {         //this event fire when click on button on form2         textbox1.text = text;     } } 

form2.cs

public partial class form2 : form {     public delegate void textenteredhandler(string text);     public event textenteredhandler ontextenteredhandler;     public form2()     {         initializecomponent();     }      private void button1_click(object sender, eventargs e)     {         if (ontextenteredhandler != null)         {             ontextenteredhandler(textbox1.text);             close();         }     } } 

you need add textbox in form 2 well, put text form 2 click button shown in code.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -