3 de dez. de 2004

Como desenhar texto rotacionado em VB.NET?

Duncan Mackenzie escreveu sobre como desenhar texto rotacionado. O exemplo, em VB.NET, é:

1 Public Enum Direction As Integer 2 N = 0 3 NE = 1 4 E = 2 5 SE = 3 6 S = 4 7 SW = 5 8 W = 6 9 NW = 7 10 End Enum 11 12 Protected Overrides Sub OnPaint(ByVal e As 13 System.Windows.Forms.PaintEventArgs) 14 15 e.Graphics.Clear(Me.BackColor) 16 17 Dim bounds As Rectangle 18 Dim g As Graphics 19 Dim rotation As Single = 0 20 21 g = e.Graphics 22 bounds = New Rectangle(50, 50, Me.Width - 100, 23 Me.Height - 100) 24 25 Dim rect As System.Drawing.RectangleF 26 27 g.DrawEllipse(Pens.Black, bounds) 28 29 Dim myMatrix As Drawing2D.Matrix 30 Dim sf As New StringFormat(StringFormatFlags.NoWrap) 31 32 sf.Alignment = StringAlignment.Center 33 myMatrix = g.Transform() 34 rect = New System.Drawing.RectangleF(bounds.X, 35 bounds.Y, bounds.Width, bounds.Height) 36 37 For i As Integer = 0 To 7 38 If i > 0 Then 39 myMatrix.RotateAt(45, 40 New PointF(Me.Width / 2, Me.Height / 2), 41 Drawing.Drawing2D.MatrixOrder.Append) 42 g.Transform = myMatrix 43 End If 44 45 Dim directionString As String 46 47 directionString = 48 System.Enum.GetName(GetType(Direction), i) 49 g.DrawString(directionString, 50 New Font("Arial", 12, FontStyle.Bold), 51 Brushes.Black, rect, sf) 52 Next 53 End Sub

Nenhum comentário: