VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > VB.net教程 >
  • VB.NET能够转动任意角度的LABEL控件代码

'  =================================================
'  ファイル名: crlRotateLabel.vb
'  機能概要  : 
'  変更履歴  : 2006/12/13 SSIT YCK263 新規作成
'  =================================================
 Public   Class crlRotateLabel
    Inherits System.Windows.Forms.Label
    Private _rotationAngle As Integer
    Private _quadrantMode As Boolean

'================================================================================
'
' 機能   :<ラベル回転の角度>
'
' 機能説明 :<ラベル回転の角度>
'
'--------------------------------------------------------------------------------
' 作成情報   : 2006/12/13 SSIT YCK263
'================================================================================    
Public Property rotationAngle() As Integer
    Get
        Return _rotationAngle
    End Get
    Set(ByVal Value As Integer)
        _rotationAngle = Value
        MyBase.Refresh()
    End Set
End Property
'================================================================================
'
' 機能   :<四分儀>
'
' 機能説明 :<四分儀>
'
'--------------------------------------------------------------------------------
' 作成情報   : 2006/12/13 SSIT YCK263
'================================================================================    
Public Property quadrantMode() As Boolean
    Get
        Return _quadrantMode
    End Get
    Set(ByVal Value As Boolean)
        _quadrantMode = Value
        MyBase.Refresh()
    End Set
End Property
'================================================================================
'
' 機能   :<再絵ラベル>
'
' 機能説明 :<再絵ラベル>
'
'--------------------------------------------------------------------------------
' 作成情報   : 2006/12/13 SSIT YCK263
'================================================================================  

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    Try
        'variables to capture the size of the text area
        Dim width As Double = e.Graphics.MeasureString(Text, Me.Font).Width
        Dim height As Double = e.Graphics.MeasureString(Text, Me.Font).Height
        'convert the rotation angle into radians for trig functions
        Dim angleRadian As Double = ((_rotationAngle Mod 360) / 180) * Math.PI
        'capture the forground color as a brush
        Dim myBrush As Brush = New SolidBrush(Me.ForeColor)

        If _quadrantMode = True Then
            'Quad I
            If (_rotationAngle >= 0 AndAlso _rotationAngle < 90) Or (_rotationAngle < -270 AndAlso _rotationAngle >= -360) Then
                e.Graphics.TranslateTransform(CInt(Math.Sin(angleRadian) * height), 0)
                'Quad II
            ElseIf (_rotationAngle >= 90 AndAlso _rotationAngle < 180) Or (_rotationAngle < -180 AndAlso _rotationAngle >= -270) Then
                e.Graphics.TranslateTransform(ClientRectangle.Width, CInt(height - (Math.Sin(angleRadian) * height)))
                'Quad III
            ElseIf (_rotationAngle >= 180 AndAlso _rotationAngle < 270) Or (_rotationAngle < -90 AndAlso _rotationAngle >= -180) Then
                e.Graphics.TranslateTransform(ClientRectangle.Width + CInt(Math.Sin(angleRadian) * height), ClientRectangle.Height)
            Else 'Quad IV
                e.Graphics.TranslateTransform(0, ClientRectangle.Height - CInt(Math.Cos(angleRadian) * height))
            End If
        Else 'Center Mode
            e.Graphics.TranslateTransform(CInt((ClientRectangle.Width + (height * Math.Sin(angleRadian)) - (width * Math.Cos(angleRadian))) / 2), CInt((ClientRectangle.Height - (height * Math.Cos(angleRadian)) - (width * Math.Sin(angleRadian))) / 2))
        End If
        e.Graphics.RotateTransform(CInt(_rotationAngle))
        e.Graphics.DrawString(Me.Text, Me.Font, myBrush, 0, 0)
        e.Graphics.ResetTransform()
    Catch ex As Exception



    End Try


End Sub
End Class


相关教程