WinForm User Controls

Source: Internet
Author: User

Purpose the user control contains a time control and a lable control, a ToolStrip control that displays the times every second

1. Build the user control

Create a new project type for the user control

Note defining the class name, which is named after the name shown in the toolbox, is defined here as the class name Labeltime. The file name is called UserControl1.cs (irrelevant, vs reference DLL when it is concerned with the class name is not a file name)

namespace myWindowsFormsControlLibrary1
{
     Public class Labeltime:usercontrol
    {
         public Labeltime ()
        {
            InitializeComponent ();
            true;
            Timer1. Interval = 1000;
        }
        Private void Timer1_Tick (object sender, EventArgs e)
        {
            this. Toolstriplabel1.text = "" + DateTime.Now.ToString ();
            This.toolStripLabel2.Text = "Server time:";
        }
        Private void Usercontrol1_load (object sender, EventArgs e)
        {
        }
        Private void Toolstriplabel1_click (object sender, EventArgs e)
        {
        }
    }
}

Right-click the build project and the following file MyWindowsFormControlLibrary.dll appears in the Bin folder, which is the control that the WinForm project will refer to later.

2. Adding user controls to the toolbar

VS Menu---> Tools----> select Toolbox items

Click Browse, select the DLL path you just made, and this control will appear in the toolbox later.

3. Using controls in projects

Test, create a new project WinForm type, and then click Open Toolbox to find that MyWindowsFormsControlLibrary1 is a named control for just the project, Labeltime is the name of the class

And then we can use it.

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.