Create your own separator controls (LineH, LineV)

Source: Internet
Author: User
In the past, when developing software using Delphi, if you need to place a separation line on the interface, the built-in TBevel can meet this requirement well. Now I switched to the. NET platform and couldn't find the corresponding control (after all, it is too troublesome to draw in the painting event every time ). However, if Panel, GroupBox, and Label are used for indirect implementation, the effect is not ideal and it feels strange. Therefore, we decided to implement a separator control, as shown in the following figure:

Here I only paste the core code. For more information about creating custom controls, see MSDN:
Ms-help: // MS. VSCC.2003/MS. MSDNQTR.2003FEB. 2052/vbcon/html/vbconControlCreation.htm
/// <Summary>
/// Horizontal separator
/// </Summary>
[
ToolboxBitmap (typeof (LineH), "res. LineH. ico "),
Designer (typeof (LineHDesigner ))
]
Public class LineH: System. Windows. Forms. UserControl
{
//......

Private void LineH_Paint (object sender, System. Windows. Forms. PaintEventArgs e)
{
Graphics g = e. Graphics;
Rectangle r = this. ClientRectangle;

Pen darkPen = new Pen (SystemColors. ControlDark, 1 );
Pen LightPen = new Pen (Color. White );

// Use a dark color to process the upper edge
G. DrawLine (darkPen, r. Left, r. Top, r. Right, r. Top );

// Use bright colors to process the lower edge
G. DrawLine (LightPen, r. Left, r. Top + 1, r. Right, r. Top + 1 );
}

//......
}
/// <Summary>
/// Vertical separator
/// </Summary>
[
ToolboxBitmap (typeof (LineV), "res. LineV. ico "),
Designer (typeof (LineVDesigner ))
]
Public class LineV: System. Windows. Forms. UserControl
{
//......

Private void LineV_Paint (object sender, System. Windows. Forms. PaintEventArgs e)

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.