The horizontal separator is used in the form, and many people use groupbox or label to simulate it. This has both advantages and disadvantages. The advantage is that it is simple. The disadvantage is that it is difficult to control the size of many lines.
Using System. componentmodel;
Using System. drawing;
Using System. Windows. forms;
Public Class Horizontalline: Control
{
Private Color _ linecolor;
[Category ( " Layout " ), Description ( " Widget size (in pixels ). " )]
Public New Size size
{
Get
{
Return Base . Size;
}
Set
{
// Note that the height of this control is already inCodeIs fixed to death, no matter how the modification is 3 pixels, if too small, you can manually modify the following code.
Setbounds (location. X, location. Y, value. Width, 3 , Boundsspecified. size );
}
}
Public New Color backcolor
{
Get { Return Base . Backcolor ;}
Set
{
Base . Backcolor = Color. transparent;
}
}
Protected Override Void Onpaint (painteventargs E)
{
Base . Onpaint (E );
Graphics g = E. graphics;
Rectangle R = E. cliprectangle;
Point left = New Point (R. Location. X, R. Location. Y + 1 );
Point right = New Point (R. Location. x + R. Width, R. Location. Y + 1 );
// The following code is # cccccc color code, which is dark gray. You can manually modify the code or extend it to attributes.
_ Linecolor = Color. fromargb ( 204 , 204 , 204 );
Pen = New Pen ( New Solidbrush (_ linecolor ), 1.5f );
G. drawline (pen, left, right );
Pen. Dispose ();
}
}