当前位置:编程学习 > C#/ASP.NET >>

在VB.NET中定制一个3D的Label的源码

答案:Public Class Lebel3D
    Inherits System.Windows.Forms.UserControl  
#Region " Windows 窗体设计器生成的代码 "  
    Public Sub New()
        MyBase.New()  
        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()  
        '在 InitializeComponent() 调用之后添加任何初始化
        mCaption = "Label3D"
        mAlignment = Align.CenterMiddle
        mAutoSize = False
        mEffect = Effect3D.Raised
        setstyle(ControlStyles.ResizeRedraw, True)
    End Sub  
    'UserControl1 重写 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()        '
        Me.Name = "Label3D"  
    End Sub  
#End Region  
    Private Shared mAlignment As Align
    Private Shared mAutoSize As Boolean
    Private Shared mEffect As Effect3D
    Private mCaption As String  
    Public Property Alignment() As Align
        Get
            Return mAlignment
        End Get
        Set(ByVal Value As Align)
            mAlignment = Value
            Invalidate()
        End Set
    End Property  
    Public Property AutoSize() As Boolean
        Get
            Return mAutoSize
        End Get
        Set(ByVal Value As Boolean)
            mAutoSize = Value
            Invalidate()
        End Set
    End Property  
    Public Property Effect() As Effect3D
        Get
            Return mEffect
        End Get
        Set(ByVal Value As Effect3D)
            mEffect = Value
            Invalidate()
        End Set
    End Property  
    Public Property Caption() As String
        Get
            Return mCaption
        End Get
        Set(ByVal Value As String)
            mCaption = Value
            Invalidate()
        End Set
    End Property  
    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim lblFont As Font = Me.Font
        Dim lblBrush As New SolidBrush(Color.Red)
        Dim X, Y As Integer
        Dim textSize As SizeF  
        textSize = e.Graphics.MeasureString(mCaption, lblFont)  
        If mAutoSize Then
            Me.Width = textSize.Width
            Me.Height = textSize.Height
        End If  
        Select Case Me.mAlignment
            Case Align.BottomLeft
                X = 0
                Y = Me.Height - textSize.Height
            Case Align.BottomMiddle
                X = CInt((Me.Width - textSize.Width) / 2)
                Y = Me.Height - textSize.Height
            Case Align.BottomRight
                X = Me.Width - textSize.Width '- 2
                Y = Me.Height - textSize.Height
            Case Align.CenterLeft
                X = 0
                Y = (Me.Height - textSize.Height) / 2
            Case Align.CenterMiddle
                X = CInt((Me.Width - textSize.Width) / 2)
                Y = (Me.Height - textSize.Height) / 2
            Case Align.CenterRight
          &

上一个:转贴自MS:扩展 TreeView 控件 (2)
下一个:校验控件出现问题,修复的方法

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,