Summary of values between C # forms

Source: Internet
Author: User

Summary of values between C # forms

1. The parent form passes the value to the subform

Write in the parent form:

Formchild FC = new Formchil ();//Create a new sub-form FC. ShowDialog (this);//The connection between the subform and the parent form is realized by the above sentence TextBox2.Text = FC. str1;//has been contacted, can be transmitted value

2. The subform passes the value to the parent form


There are two ways of doing this:

(1) write in the subform:

   Formparent fp = (formparent) this. owner;//Implementation Contact     TextBox1.Text = fp. str1;//has been contacted, can be transmitted value

(2) using the subform's constructor to pass in the parent form's value (code below), you can pass the value of one or two parent form, if you want to pass the value can use ArrayList, also can pass the form directly (sample code directly to the form)

Summary: Grab the Form object and the link to pass the value

Code:

Using system.data;using system.drawing;using system.linq;using system.text;using system.windows.forms;namespace            testtransvalue{public partial class Form1:form {private string form1text;                    public string Form1text {get {return form1text;}        set {Form1text = value;}            } public Form1 () {InitializeComponent ();        Form1text = "This is the text from Form1"; private void Form1_Load (object sender, EventArgs e) {} private void Button1_cli            CK (object sender, EventArgs e) {Form2 F2 = new Form2 (); F2.            ShowDialog (this); TextBox1.Text = F2.        form2text;//above three sentences can be achieved from the subform to the parent form of the value of} private void Button2_Click (object sender, EventArgs e)            {Form3 F3 = new FORM3 (this); F3.            ShowDialog (this); TextBox2.Text = F3. form3text;//above three sentences can be implemented from the subform to the parent form of the value of}}}


Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace testtransvalue{public    partial class Form3:form    {        private string form3text = "This is the text from FORM3";        Form1 F1;        public string Form3text        {            get {return form3text;}                    set {Form3text = value;}        }        Public Form3 (Form1 Form1)        {            InitializeComponent ();            F1 = form1;        }        private void Form3_load (object sender, EventArgs e)        {        }        private void Button1_Click (object sender, EventArgs e)        {            TextBox1.Text = F1. Form1text;}}}    

The above is the C # form the summary of the value of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.