I want to draw 1000 random circles.
During the loop, I also want to update a label to display a counter.
If I do Me.Refresh() in the loop, all the drawing is lost.
What is the correct way?
During the loop, I also want to update a label to display a counter.
If I do Me.Refresh() in the loop, all the drawing is lost.
What is the correct way?
Code:
Public Class Form1
Public myPen As Pen
Public myGraphics As Graphics
Public generator As New Random
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
myPen = New Pen(Drawing.Color.Black, 1)
myGraphics = Me.CreateGraphics
End Sub
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
Dim x As Integer
Dim y As Integer
For i = 1 To 1000
x = generator.Next(0, 100)
y = generator.Next(0, 100)
myGraphics.DrawEllipse(myPen, x, y, 1, 1)
'This displays the count.
'Alone, it does not update until the 1000 loop is done
Label1.Text = i
'This forces the label refresh, but all circles are lost.
'Me.Refresh()
Next
End Sub
End Class