Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles _
MyBase.Paint
e.Graphics.DrawImage(m_Bitmap, 0, 0)
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles MyBase.Resize
m_Bitmap = MakeBitmap()
Me.Invalidate()
End Sub
' Make a bitmap displaying the image.
Private Function MakeBitmap() As Bitmap
Const RADIUS As Single = 12
Const WID As Single = 2 * RADIUS
Dim max_r As Integer
Dim max_c As Integer
Dim X As Single
Dim Y As Single
Dim bm As New Bitmap(Me.ClientSize.Width, _
Me.ClientSize.Height)
Dim gr As Graphics = Graphics.FromImage(bm)
gr.Clear(Me.BackColor)
max_c = ClientRectangle.Width \ WID + 1
max_r = ClientRectangle.Height \ WID + 1
Y = 0
For r As Integer = 0 To max_r
X = 0
For c As Integer = 0 To max_c
' Note that angles are in clockwise degrees.
If m_Random.Next(0, 2) = 0 Then
gr.DrawArc(Pens.Black, X - RADIUS, Y - _
RADIUS, WID, WID, 0, 90)
gr.DrawArc(Pens.Black, X + RADIUS, Y + _
RADIUS, WID, WID, 180, 90)
Else
gr.DrawArc(Pens.Black, X - RADIUS, Y + _
RADIUS, WID, WID, 270, 90)
gr.DrawArc(Pens.Black, X + RADIUS, Y - _
RADIUS, WID, WID, 90, 90)
End If
X = X + WID
Next c
Y = Y + WID
Next r
gr.DrawRectangle(Pens.Black, 0, 0, Me.ClientSize.Width, _
Me.ClientSize.Height)
gr.Dispose()
Return bm
End Function
|