To reduce flicker, the program's Form_Load event handler makes the form use double buffering.
When the tmRotate Timer control's Tick event fires, the event handler invalidates the form so its Paint event handler executes.
The Paint event handler applies a rotation to the Graphics object that will produce the text. It then applies a translation to move the origin to the form's center. It then prints the text at the origin (now rotated and translated). It uses a StringFormat object to center the text at the origin.
|
Private m_Angle As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
e As System.EventArgs) Handles MyBase.Load
' Double buffer.
Me.SetStyle( _
ControlStyles.AllPaintingInWmPaint Or _
ControlStyles.UserPaint Or _
ControlStyles.DoubleBuffer, _
True)
Me.UpdateStyles()
Me.Font = New Font("Times New Roman", 80)
End Sub
Private Sub tmRotate_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles tmRotate.Tick
Me.Invalidate()
End Sub
' Draw the rotated text.
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles _
MyBase.Paint
m_Angle += 2
Dim string_format As New StringFormat
string_format.Alignment = StringAlignment.Center
string_format.LineAlignment = StringAlignment.Center
e.Graphics.RotateTransform(m_Angle)
e.Graphics.TranslateTransform( _
Me.ClientSize.Width / 2, _
Me.ClientSize.Height / 2, _
Drawing2D.MatrixOrder.Append)
e.Graphics.DrawString( _
"M", Me.Font, Brushes.Black, _
0, 0, string_format)
End Sub
|