Developing a Windows Control Library - Digital Clock


Creating a new Control 

A Windows control library is similar to an ActiveX Control that you have been developing using VC++. In VS.NET IDE environment, controls can be found by clicking the toolbox icon. Windows controls can be either UI controls like "Edit" , "Label" , "ListBox" etc (Found under the Windows Forms Tab ) or non UI controls like Timers ( found under the Components Tab).To create a control under the VS .NET IDE environment , create a new project of the type Windows Control Library.

Within the control , use the Paint event to do all the drawing.

private void UserControl1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
cc.Set_Time(hour , min , sec ,e.ClipRectangle ,e.Graphics, foreColor );
}

A timer is used to update the current time every second and invalidate the control.

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
RefreshTime(
ref hour , ref min ,ref sec);
Invalidate() ;
}

Adding the control to ToolBox List

Once the control is created you can add the control to the ToolBox ( Windows Forms tab ) by right clicking on the toolbox and selecting the "Customize Toolbox.. / .Net Framework Components Tab". Browse for the DLL that you have created and click OK.

Using the Control

The "User Control" will be added to the end of the list. Once you have added the control to the ToolBox, just drag and drop the control into the Windows Form.

You can use the property tab to set the fore color and the back color of the control. 

Up Next
    Ebook Download
    View all
    Learn
    View all