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.