C#winform making user controls + passing values to user controls

Source: Internet
Author: User

The first use is to put a form on another form, such as code, and later found that it is very card, the interface to move or adjust will not come back.

 // basicin bi = new Basicin (a);  // bi. TopLevel = false;  //  to load the form when the control must be  //            splitcontainer3.panel1.controls.clear ();  // splitcontainer3.panel1.controls.add            (BI);  // bi.            Dock = DockStyle.Fill;  // bi.            BringToFront ();             // this.ds = bi;  // bi. Show ();  

Therefore, use the user control instead.

First, the steps to make a user control

1, create a new project, File New project.

2, add the new item user control.

3. Set the code you need.

4. Run the program. Locate the appropriate. dll file under the Debug folder.

Second, there are two ways to use a user control

1. Locate the. dll file. In the Toolbox, right-click on "select". NET Framework Components Browse, locate the. dll file to add, the Toolbox will automatically display the user control, just drag and drop it. Cons: The need to modify the user control is to rebuild the DLL file, trouble.

2, right-click on your own project's solution add the existing item, add the user control, and use the edge to change.

All right.

If you want to pass the value of the window to the user control,

1,get,set method.

User controls:

        Public Static string NULL ;          Public void Setlab (string  _tipdou)        {            = _tipdou;            ShowData (Tipdou);        }          Public Static string Getlab ()        {            return  Tipdou;        }

Window:

      Usercontrol11.setlab ("a");

2, method parameter pass value,,,

User controls:

public void AddData (string b)
{
Sarrry = Mystr.split (new char[] {' * '}, 7, stringsplitoptions.none);
if (b = = "Style")
{

This.adddatarow ();
}
if (b = = "Color")
{
This.adddatarow1 ();
}

if (b = = "Size")
{
This.adddatarow2 ();

}
}

Window:

   Usercontrol11.adddata ("a");

C#winform making user controls + passing values to user controls

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.