如何制作分隔线控件?
新建一个VisualBasic的Windows控件库。在项目中添加两个用户控件,一个为:LineH水平分隔线,一个为:LineV垂直分隔线,代码如下。经过生成.dll,在其他项目引用,就可以使用。
分割线控件下载地址:http://download.csdn.net/source/1447072
在界面中使用分割线的例子:看日期下面的分割线。
=============水平分隔线LineH.vb的完整代码=============
''''水平分隔线LineH.vb的完整代码
PublicClassLineH
InheritsSystem.Windows.Forms.UserControl
"Windows窗体设计器生成的代码"
PrivateSubLineH_Paint(ByValsenderAsObject,ByValeAsPaintEventArgs)HandlesMyBase.Paint
DimgAsGraphics=e.Graphics
DimrAsRectangle=Me.ClientRectangle
DimdarkPenAsPen=NewPen(SystemColors.ControlDark,1)
DimLightPenAsPen=NewPen(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)
EndSub
EndClass
PublicClassLineH
InheritsSystem.Windows.Forms.UserControl
"Windows窗体设计器生成的代码"
PrivateSubLineH_Paint(ByValsenderAsObject,ByValeAsPaintEventArgs)HandlesMyBase.Paint
DimgAsGraphics=e.Graphics
DimrAsRectangle=Me.ClientRectangle
DimdarkPenAsPen=NewPen(SystemColors.ControlDark,1)
DimLightPenAsPen=NewPen(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)
EndSub
EndClass
=============垂直分隔线LineV.vb的完整代码=============
''''垂直分隔线LineV.vb的完整代码
PublicClassLineV
InheritsSystem.Windows.Forms.UserControl
"Windows窗体设计器生成的代码"
PrivateSubLineV_Paint(ByValsenderAsObject,ByValeAsPaintEventArgs)HandlesMyBase.Paint
DimgAsGraphics=e.Graphics
DimrAsRectangle=Me.ClientRectangle
DimdarkPenAsPen=NewPen(SystemColors.ControlDark,1)
DimLightPenAsPen=NewPen(Color.White)
''''用暗色调处理左边缘
g.DrawLine(darkPen,r.Left,r.Top,r.Left,r.Bottom)
''''用亮色调处理右边缘
g.DrawLine(LightPen,r.Left+1,r.Top,r.Left+1,r.Bottom)
EndSub
EndClass
PublicClassLineV
InheritsSystem.Windows.Forms.UserControl
"Windows窗体设计器生成的代码"
PrivateSubLineV_Paint(ByValsenderAsObject,ByValeAsPaintEventArgs)HandlesMyBase.Paint
DimgAsGraphics=e.Graphics
DimrAsRectangle=Me.ClientRectangle
DimdarkPenAsPen=NewPen(SystemColors.ControlDark,1)
DimLightPenAsPen=NewPen(Color.White)
''''用暗色调处理左边缘
g.DrawLine(darkPen,r.Left,r.Top,r.Left,r.Bottom)
''''用亮色调处理右边缘
g.DrawLine(LightPen,r.Left+1,r.Top,r.Left+1,r.Bottom)
EndSub
EndClass
在win2000+vs2003编译通过。
本文地址:http://www.45fan.com/dnjc/69257.html