.NET开发

本类阅读TOP10

·NHibernate快速指南(翻译)
·vs.net 2005中文版下载地址收藏
·【小技巧】一个判断session是否过期的小技巧
·VB/ASP 调用 SQL Server 的存储过程
·?dos下编译.net程序找不到csc.exe文件
·通过Web Services上传和下载文件
·学习笔记(补)《.NET框架程序设计(修订版)》--目录
·VB.NET实现DirectDraw9 (2) 动画
·VB.NET实现DirectDraw9 (1) 托管的DDraw
·建站框架规范书之——文件命名

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
VB.NET中的Line控件

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

在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 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'Line
        '
        Me.Name = "Line"
        Me.Size = New System.Drawing.Size(304, 72)
    End Sub
#End Region
#Region " 属性 "
    <System.ComponentModel.Description("直线类型:" & vbCrLf & "Tf   '凸" & vbCrLf & "Ft   '凹" & vbCrLf & "Flat   '平面")> Public Property LineType() As Type
        Get
            LineType = LineT
        End Get
        Set(ByVal Value As Type)
            LineT = Value
        End Set
    End Property
    <System.ComponentModel.Description("上线颜色")> Public Property TopLineColor() As System.Drawing.Color
        Get
            TopLineColor = TopLC
        End Get
        Set(ByVal Value As System.Drawing.Color)
            TopLC = Value
        End Set
    End Property
    <System.ComponentModel.Description("下线颜色")> Public Property FootLineColor() As System.Drawing.Color
        Get
            FootLineColor = FootLC
        End Get
        Set(ByVal Value As System.Drawing.Color)
            FootLC = Value
        End Set
    End Property
#End Region
    Private Sub Line_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim TopLine As New Pen(Me.TopLineColor)
        Dim FootLine As New Pen(Me.FootLineColor)
        Dim startX As Integer
        Dim startY As Integer
        Select Case LineT
            Case LineT.Flat
                e.Graphics.DrawLine(TopLine, 0 + startX, 0, Me.Width + startX, 0)
                e.Graphics.DrawLine(TopLine, 1 + startX, 1, Me.Width + startX, 1)
            Case LineT.Tf
                e.Graphics.DrawLine(TopLine, 0 + startX, 0, Me.Width + startX, 0)
                e.Graphics.DrawLine(FootLine, 1 + startX, 1, Me.Width + startX, 1)
            Case LineT.Ft
                e.Graphics.DrawLine(FootLine, 0 + startX, 0, Me.Width + startX, 0)
                e.Graphics.DrawLine(TopLine, 1 + startX, 1, Me.Width + startX, 1)
        End Select
    End Sub
    Private Sub Line_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        Me.Height = 2
    End Sub
End Class

新建一个类,把以上代码粘贴即可。


欢迎大家改进代码,别忘了也发给俺一份





相关文章

相关软件