在这里我只将核心代码贴出来,关于创建自定义控件的相关知识可参考MSDN:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vbconControlCreation.htm
///
/// 水平分隔线
///
[
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);
//用暗色调处理上边缘
g.DrawLine(darkPen, r.Left, r.Top, r.Right, r.Top);
//用亮色调处理下边缘
g.DrawLine(LightPen, r.Left, r.Top + 1, r.Right, r.Top + 1);
}
//... ...
}
///
/// 垂直分隔线
///
[
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)
制作自己的分辨率|制作自己的分隔线控件(LineH、LineV)
http://m.bbyears.com/wangyezhizuo/5232.html
推荐访问: