** 在VB.NET中去掉了Line控件,我们用.NET转换包含有Line控件的VB6的工程后,发现取而代之的是Label。 **
** 其实我们还可以有另一种画线的方法: **
Public Class Line
Inherits System.Windows.Forms.UserControl
Public TopLC As System.Drawing.Color = System.Drawing.Color.White '上线颜色
Public FootLC As System.Drawing.Color = System.Drawing.Color.Black '下线颜色
Public LineT As Type '直线类型
Public Enum Type
Tf '凸
Ft '凹
Flat '平面
End Enum
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'UserControl 重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
1<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
2'
3'Line
4'
5Me.Name = "Line"
6Me.Size = New System.Drawing.Size(304, 72)
7End Sub
8#End Region
9#Region " 属性 "
10<system.componentmodel.description("直线类型:" "flat="" "ft="" "tf="" &="" '凸"="" '凹"="" '平面")="" vbcrlf=""> Public Property LineType() As Type
11Get
12LineType = LineT
13End Get
14Set(ByVal Value As Type)
15LineT = Value
16End Set
17End Property
18<system.componentmodel.description("上线颜色")> Public Property TopLineColor() As System.Drawing.Color
19Get
20TopLineColor = TopLC
21End Get
22Set(ByVal Value As System.Drawing.Color)
23TopLC = Value
24End Set
25End Property
26<system.componentmodel.description("下线颜色")> Public Property FootLineColor() As System.Drawing.Color
27Get
28FootLineColor = FootLC
29End Get
30Set(ByVal Value As System.Drawing.Color)
31FootLC = Value
32End Set
33End Property
34#End Region
35Private Sub Line_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
36Dim TopLine As New Pen(Me.TopLineColor)
37Dim FootLine As New Pen(Me.FootLineColor)
38Dim startX As Integer
39Dim startY As Integer
40Select Case LineT
41Case LineT.Flat
42e.Graphics.DrawLine(TopLine, 0 + startX, 0, Me.Width + startX, 0)
43e.Graphics.DrawLine(TopLine, 1 + startX, 1, Me.Width + startX, 1)
44Case LineT.Tf
45e.Graphics.DrawLine(TopLine, 0 + startX, 0, Me.Width + startX, 0)
46e.Graphics.DrawLine(FootLine, 1 + startX, 1, Me.Width + startX, 1)
47Case LineT.Ft
48e.Graphics.DrawLine(FootLine, 0 + startX, 0, Me.Width + startX, 0)
49e.Graphics.DrawLine(TopLine, 1 + startX, 1, Me.Width + startX, 1)
50End Select
51End Sub
52Private Sub Line_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
53Me.Height = 2
54End Sub
55End Class
56---
57
58
59
60**新建一个类,把以上代码粘贴即可。**
61
62
63**欢迎大家改进代码,别忘了也发给俺一份 **</system.componentmodel.description("下线颜色")></system.componentmodel.description("上线颜色")></system.componentmodel.description("直线类型:"></system.diagnostics.debuggerstepthrough()>