How to transfer values between forms in asp.net winform

Source: Internet
Author: User

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
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.