Public Class Form1 End Class Public Class FlipLabel Inherits Label Public Sub Flip0() Me.Degree = 0 End Sub Public Sub Flip90() Me.Degree = 90 End Sub Public Sub Flip180() Me.Degree = 180 End Sub Public Sub Flip270() Me.Degree = 270 End Sub Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs) Dim offsetX As Integer Dim offsetY As Integer Select Case Degree Case 90 offsetX = (e.Graphics.MeasureString(Me.Text, Me.Font)).Width Case 180 offsetX = (e.Graphics.MeasureString(Me.Text, Me.Font)).Width offsetY = (e.Graphics.MeasureString(Me.Text, Me.Font)).Height Case 270 offsetY = (e.Graphics.MeasureString(Me.Text, Me.Font)).Height End Select e.Graphics.TranslateTransform(offsetX, offsetY) e.Graphics.RotateTransform(degree) e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), New Point(0, 0)) End Sub Private degreeValue As Single Protected Property Degree As Single Get Return degreeValue End Get Set(value As Single) degreeValue = value Invalidate() End Set End Property End Class
Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click FlipLabel1.Flip90() End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click FlipLabel1.Flip180() End Sub Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click FlipLabel1.Flip270() End Sub Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load FlipLabel1.Text = "58" End Sub End Class
Label1.RenderTransform = New RotateTransform(50)