-
1 Attachment(s)
Form Draw Demo
An example on how to draw onto a form. I used iteration to draw a grid and a grid of circles to the form. Comment out different loops for different draw styles. You can download the attachment with the project for just paste the code into a blank form on a new project. Written with vb 2008 express.
Code:
Public Class Form1
Private Sub Form1_Paint(ByVal sender As Object, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
'comment out different for/next loops to see different drawing methods
Dim i As Integer = 0
Dim y As Integer = 0
Me.BackColor() = Color.Green
'iteration to draw horizontal lines
For i = 0 To Me.Height Step 10
e.Graphics.DrawLine(Pens.Red, 0, i, Me.Width, i)
Next i
'iteration to draw vertical lines
For i = 1 To Me.Width Step 10
e.Graphics.DrawLine(Pens.Red, i, 0, i, Me.Height)
Next i
'iteration to draw ellipses
For y = 0 To Me.Height Step 10
For i = 1 To Me.Width Step 10
e.Graphics.DrawEllipse(Pens.Blue, i, y, 10, 10)
Next i
Next y
End Sub
End Class