Make your own separator line control (Lineh, Linev)

Source: Internet
Author: User
Control before using Delphi to develop software, if you need to place a divider line on the interface, its tbevel can well meet this requirement. Now turn to the. NET platform, you can not find the corresponding control (after all, every time in the paint incident painting too much trouble). And if Use panel, GroupBox, label to realize indirectly, the effect is not ideal, and feel strange. So you decide to implement a separator line control yourself, as shown in the following illustration:








Here I only post the core code, and the relevant knowledge about creating custom controls can be referenced in MSDN:

Ms-help://ms. Vscc.2003/ms. Msdnqtr.2003feb.2052/vbcon/html/vbconcontrolcreation.htm



<summary>

Horizontal Divider Line

</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 dark tones to handle upper edges

G.drawline (Darkpen, R.left, R.top, R.right, r.top);



Handle the bottom edge with a bright tint

G.drawline (Lightpen, R.left, R.top + 1, r.right, r.top + 1);

}


//... ...

}




<summary>

Vertical Divider Line

</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)

{

Graphics g = e.graphics;

Rectangle r = this. ClientRectangle;



Pen Darkpen = new Pen (systemcolors.controldark, 1);

Pen Lightpen = new Pen (color.white);



Using dark tones to handle the left edge

G.drawline (Darkpen, R.left, R.top, R.left, R.bottom);



Handle right edge with light tone
G.drawline (Lightpen, R.left + 1, r.top, R.left + 1, r.bottom);

}

//... ...

}





To fully implement the effect shown above, refer to http://blog.csdn.net/doubon/archive/2005/01/18/258314.aspx.





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.