Asp tutorial on how to pass values between forms in. net winform
Use attribute
Public partial class form1: form
{
Private void button#click (object sender, eventargs e)
{
Form2 frm2 = new form2 ();
Frm2.show (this );
}
}
Public partial class form2: form
{
Private void button#click (object sender, eventargs e)
{
Form1 frm1 = (form1) this. owner;
(Textbox) frm1.controls ["textbox1"]). text = this. textbox2.text;
This. close ();
}
}
You can also use Delegation
Use a delegate to implement interaction between two forms:
// In the main form
Fromb frm = new fromb ("hello ");
Frm. onreportprogress = new doreportss (onreportprogress );
Frm. showdialog (); // display form
Private void onreportprogress (string str)
{
Messagebox. show (str );
}
// Subform
Public delegate void doreportss (string strinfor );
Public doreportss onreportprogress;
Public fromb (string str) // input the value of the parent form
{
Initializecomponent ();
Messagebox. show (str );
}
Public void button1 ()
{
If (onreportprogress! = Null)
Onreportprogress ("hello B"); // call the delegate to return the value to the parent form
}