如何制作分隔线控件?
新建一个VisualBasic的Windows控件库。在项目中添加两个用户控件,一个为:LineH水平分隔线,一个为:LineV垂直分隔线,代码如下。经过生成.dll,在其他项目引用,就可以使用。
分割线控件下载地址:http://download.csdn.net/source/1447072
在界面中使用分割线的例子:看日期下面的分割线。

=============水平分隔线LineH.vb的完整代码=============
''''水平分隔线LineH.vb的完整代码

PublicClassLineHClassLineH
InheritsSystem.Windows.Forms.UserControl


"Windows窗体设计器生成的代码"#Region"Windows窗体设计器生成的代码"


PublicSubNew()SubNew()
MyBase.New()

''''该调用是Windows窗体设计器所必需的。
InitializeComponent()

''''在InitializeComponent()调用之后添加任何初始化

EndSub

''''UserControl1重写dispose以清理组件列表。

ProtectedOverloadsOverridesSubDispose()SubDispose(ByValdisposingAsBoolean)
IfdisposingThen
IfNot(componentsIsNothing)Then
components.Dispose()
EndIf
EndIf
MyBase.Dispose(disposing)
EndSub

''''Windows窗体设计器所必需的
PrivatecomponentsAsSystem.ComponentModel.IContainer

''''注意:以下过程是Windows窗体设计器所必需的
''''可以使用Windows窗体设计器修改此过程。
''''不要使用代码编辑器修改它。

<System.Diagnostics.DebuggerStepThrough()>PrivateSubInitializeComponent()SubInitializeComponent()
''''
''''LineH
''''
Me.Name="LineH"
Me.Size=NewSystem.Drawing.Size(10,2)

EndSub

#EndRegion


PrivateSubLineH_Paint()SubLineH_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的完整代码

PublicClassLineVClassLineV
InheritsSystem.Windows.Forms.UserControl


"Windows窗体设计器生成的代码"#Region"Windows窗体设计器生成的代码"


PublicSubNew()SubNew()
MyBase.New()

''''该调用是Windows窗体设计器所必需的。
InitializeComponent()

''''在InitializeComponent()调用之后添加任何初始化

EndSub

''''UserControl重写dispose以清理组件列表。

ProtectedOverloadsOverridesSubDispose()SubDispose(ByValdisposingAsBoolean)
IfdisposingThen
IfNot(componentsIsNothing)Then
components.Dispose()
EndIf
EndIf
MyBase.Dispose(disposing)
EndSub

''''Windows窗体设计器所必需的
PrivatecomponentsAsSystem.ComponentModel.IContainer

''''注意:以下过程是Windows窗体设计器所必需的
''''可以使用Windows窗体设计器修改此过程。
''''不要使用代码编辑器修改它。

<System.Diagnostics.DebuggerStepThrough()>PrivateSubInitializeComponent()SubInitializeComponent()
''''
''''LineV
''''
Me.Name="LineV"
Me.Size=NewSystem.Drawing.Size(2,10)

EndSub

#EndRegion


PrivateSubLineV_Paint()SubLineV_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