C # form value passing

Source: Internet
Author: User

2. input values in the form

Form1 contains textbox1 and button1.

Lable1 in form2

To implement: click "button1" and then "form2". The content of lable1 is the content of textbox1.

ImplementedCode:

Code of the button in form1:

String T = textbox1.text; // Give the content to be displayed to a variable;

From2 Fr = new form2 (t); // form2 (t) is an overloaded constructor in form2

Fr. Show ();

Code in form2:

Private string m;

Public form2 (string P ) // Reload the constructor and add a parameter (used to pass the value) -- when the parameter is instantiated in form1 -- t is the content of textbox1.text, which replaces P

{

Initializecomponent ();

This. M = P; // Assign the parameter value to a private variable of form2

}

Form2_load ()

{

This. lable1.text = m; // Lable1 is the private variable M. At this time, M is the value T passed by form1.

}

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.