Home>

Click on button1 of form1 to open form2

Then click button2 of form2

In the button2_click event, set the value of form2's textbox2 to form1's textbox1 via this.owner

And close form2

public partial class form1:form
{
  public form1 ()
  {
   initializecomponent ();
  }
  private void button1_click (object sender, eventargs e)
  {
   form2 frm2=new form2 ();
   frm2.show (this);/or frm2.showdialog (this);
   ////or
   //form2 frm2=new form2 ();
   //frm2.owner=this;
   //frm2.show();/or frm2.showdialog ();
  }
}
public partial class form2:form
{
  public form2 ()
  {
   initializecomponent ();
  }
  private void button2_click (object sender, eventargs e)
  {
   form1 frm1=(form1) this.owner;
  //Note If textbox1 is placed in panel1, first find panel1 and then textbox1
   ((textbox) frm1.controls ["textbox1"]). text=this.textbox2.text;
   this.close ();
  }
}

Click button1 of form1 to open form2

Then click button2 of form2

In the button2_click event, pass this.owner and call the public property or method of the parent form1

Set the value of form2's textbox2 to form1's textbox1

And close form2

public partial class form1:form
{
  public form1 ()
  {
   initializecomponent ();
  }
  public string textbox1text
  {
   set {this.textbox1.text=value;}
   get {return this.textbox1.text;}
  }
  private void button1_click (object sender, eventargs e)
  {
   form2 frm2=new form2 ();
   frm2.show (this);/or frm2.showdialog (this);
   ////or
   //form2 frm2=new form2 ();
   //frm2.owner=this;
   //frm2.show();/or frm2.showdialog ();
  }
}
public partial class form2:form
{
  public form2 ()
  {
   initializecomponent ();
  }
  private void button2_click (object sender, eventargs e)
  {
   form1 frm1=(form1) this.owner;
   frm1.textbox1text=this.textbox2.text;
   this.close ();
  }
}
c
  • Previous Android implements the method of storing files in SDCard
  • Next Make simple devour effects based on replaceChild