C # How to transmit data or variables between two forms

Source: Internet
Author: User

When the child form is displayed in the parent form, add the child form. owner = this; define a parent form object in the child form, and set the parent form object = (parent form type) this in the Load function. owner. Then, use this parent form object to directly use its parameters at any position in the child form (these parameters must be defined as public ). define the parent form object as a variable of the child form. Instead of defining the parent form object in Load, you only get the parent window in Load, in this way, the parent window object can be used at any position of the child form, as shown in the following code: (1) Form2 f2 = new Form2 () in the parent form (); // create a subform object
F2.Owner = this;
// Set the owner of the subform object to Form1 (2) in the subform private void Form2_Load (object sender,
EventArgs e) // you must call
{
Form1 f1 = (Form1) this. Owner;
// Call the parent form in this way
TextBox4.Text = f1.hight. ToString ();
}

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.