Make your own divided line control (LINEH, LINEV)

xiaoxiao2021-03-06  23

In the past, when you develop software with Delphi, if you need to place a separation line on the interface, the coming TBevel can meet this requirement. Now go to the .NET platform, can't find the corresponding control (after all, painting too much in the PAINT event). If you use Panel, GroupBox, Label to indirectly, the effect is not ideal, and it feels weird. Therefore, I decide my own separation control, the effect is as shown below:

Here I only put the core code, and the relevant knowledge of the creation of custom controls can be referred to MSDN:

MS-help: //ms.vscc.2003/ms.msdnqtr.2003feb.2052/vbcon/html/vbcontrolcreation.htm

///

/// horizontal separation line

///

[

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

// Turn on the edge with dark color

G. Drawline (Darkpen, R.Left, R.top, R.right, R.TOP);

// Under the bright tone process

g.drawline (Lightpen, R.Left, R.top 1, R.right, R.top 1);

}

// ... ...

}

///

/// Vertical separation line

///

[

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

// Treat the left edge with dark color

g.drawline (Darkpen, R.Left, R.top, R.LEFT, R.BOTTOM);

// Turn the right edge G. Drawline (Lightpen, R.LEFT 1, R.TOP, R.LEFT 1, R.BOTTOM);

} // ...

}

To fully implement the effects shown in the figure, see http://blog.9cbs.net/doubon/archive/2005/01/18/258314.aspx.

转载请注明原文地址:https://www.9cbs.com/read-66240.html

New Post(0)