The source code of the control that draws horizontal separation lines in winform. Many people are using it.

Source: Internet
Author: User

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 ();
}
}

 

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.