Winform controls are divided into user controls and custom controls. User Controls are relatively simple. This article discusses custom controls.
Ms controls, both winform controls and webform controls, have the same design philosophy.
1) For custom controls:
The UI display of the winform control depends on the onprint method, while that of the webform control depends on the renderxxxx method.
2) For custom controls and user controls:
The properties of the winfrom control and webform control play a crucial role in the uidesign. You can set attributes in the design view to set the UI effect. Remember to call the invalidate (); Method to redraw the winfrom attribute set.
3) for the UI design:
Winform is drawn based on GDI +, while webform depends on familiarity with HTML.CodeReturn to the client.
The following is the code for the winfrom custom control:
Using System;
Using System. Collections. Generic;
Using System. componentmodel;
Using System. Data;
Using System. drawing;
Using System. text;
Using System. Windows. forms;
NamespaceWinformcontrol
{
Public Partial ClassLandpycontrol: Control
{
PublicLandpycontrol ()
{
Initializecomponent ();
}
PrivateColor _ textcolor;
Public Color textcolor
{
Get { Return _ Textcolor ;}
Set
{
_ Textcolor = Value;
Invalidate ();
}
}
Protected Override Void Onpaint (painteventargs PE)
{
Base . Onpaint (PE );
Font enfont = New Font ( " Times New Roman " , 12 );
Rectangle rect = PE. cliprectangle;
PE. Graphics. drawstring (text, enfont, New Solidbrush (_ textcolor ), 0 , 0 );
}
protected override void onclick (eventargs E)
{< br> base . onclick (E);
_ textcolor = color. red;
invalidate ();
}
Protected Override VoidOnmouseleave (eventargs E)
{
Base. Onmouseleave (E );
_ Textcolor=Color. Black;
Invalidate ();
}
}
}
Textcolor allows you to set the color of the displayed text and define the events of the control.
The simple winfrom custom control is complete.