ASP tutorials How to transfer values between forms in the WinForm of. Net
Use attribute
public partial class Form1:form
{
private void Button1_Click (object sender, EventArgs e)
{
Form2 frm2 = new Form2 ();
Frm2.show (this);
}
}
public partial class Form2:form
{
private void Button1_Click (object sender, EventArgs e)
{
Form1 Frm1 = (Form1) This.owner;
((textbox) frm1.controls["TextBox1"]). Text = This.textbox2.text;
This.close ();
}
}
You can also use the delegate
Use delegates to implement the interaction of two forms:
In the main form
Fromb frm = new Fromb ("Hello a");
frm.onreportprogress = new Doreportprogress (onreportprogress);
Frm.showdialog (); Show form
private void Onreportprogress (String str)
{
MessageBox.Show (str);
}
Child form
public delegate void Doreportprogress (string strinfor);
Public doreportprogress onreportprogress;
Public Fromb (String str)//Incoming value of parent form
{
InitializeComponent ();
MessageBox.Show (str);
}
public void Button1 ()
{
if (onreportprogress!=null)
Onreportprogress ("Hello B"); Calling the delegate to return the value to the parent form
}