[★] Transferring values between Windows forms using the object-oriented [attribute] Method

Source: Internet
Author: User
Tags readfile

In the past, the instructor mentioned an example of passing values by performing operations on properties in forms and classes ..
Unexpectedly, I did not find it after searching on the csdn. Web for a long time.ArticleI am inspired to write my own data transfer method ....
There are several ways to pass the value... form fm = new form (parameter) is my most disapproval ........
There is no need to delegate... the static field is too limited ..
Namespace readfile
{
Public partial class form2: Form
{

Public form2 ()
{
Initializecomponent ();
}

Private void button#click (Object sender, eventargs E)
{

Form3 fm = new form3 ();
FM. _ Val = This. textbox1.text;
If (FM. showdialog () = dialogresult. OK)
{
This. textbox1.text = FM. _ Val;
}

}
}
}

Namespace readfile
{
Public partial class form3: Form
{
// Define an attribute
Public String _ Val;
Public String Val
{
Get
{
Return _ Val;
}
Set
{
_ Val = value;
}
}

Public form3 ()
{
Initializecomponent ();
}

Private void button#click (Object sender, eventargs E)
{
_ Val = This. textbox1.text;
This. dialogresult = dialogresult. OK;
This. Hide ();
}

Private void form3_load (Object sender, eventargs E)
{
This. textbox1.text = _ Val;
}


}
}

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.