I am trying to develope a small graphics application in VB.NET. My startup form has a picture box with a background image loaded from a file. The user can click spots on the picture box and this draws some circles on it. On exit the coordinates for these spots are saved to a file.
In my form load procedure I load the background image, the coordinates for the graphics(saved from the last time the program was run), and then call the drawing procedure.
The drawings appear for an instant and then dissappear.
If you click the picture box the graphics re-appear.
The form works fine once you do this.
I guess the picture box is refreshed by the form load event and this is causing the drawings to be wiped.(I stalled the call to the drawing procedure by using a timer and this works but I am sure there is a proper way of fixing this)
Is there a way of ensuring a form is fully loaded or making sure the drawing procedure occurs only when the form is fully loaded?
HERES THE CODE:
Private Sub Form2_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
Me.Show()
Application.DoEvents()
picturebox1.BackgroundImage = System.Drawing.Image.FromFile ("C:\test.bmp")
loadspots() ' Coordinates for the drawings
DrawBoxes()
End Sub
Private Sub DrawBoxes()
Me.Refresh()
Dim m As Short
PictureBox1.Refresh()
Dim Dg As System.Drawing.Graphics
Dim FT As New Font("Arial", 10, FontStyle.Bold)
Dg = PictureBox1.CreateGraphics
For m = 0 To 5
If LbY(m).Text <> "" Then
Dg.FillEllipse(Brushes.Red, CInt(lbX(m).Text) - 10, CInt(LbY(m).Text) - 10, 20, 20)
Dg.DrawString(Str(m + 1), FT, Brushes.Black, CInt(lbX(m).Text) - 8, CInt(LbY(m).Text) - 8)
Dg.FillEllipse(Brushes.Red, CInt(lbX(m).Text) - WhiteOff - 10, CInt(LbY(m).Text) - 10, 20, 20)
End If
Next m
Dg.Dispose()
End Sub
Any Help would be appreciated.
In my form load procedure I load the background image, the coordinates for the graphics(saved from the last time the program was run), and then call the drawing procedure.
The drawings appear for an instant and then dissappear.
If you click the picture box the graphics re-appear.
The form works fine once you do this.
I guess the picture box is refreshed by the form load event and this is causing the drawings to be wiped.(I stalled the call to the drawing procedure by using a timer and this works but I am sure there is a proper way of fixing this)
Is there a way of ensuring a form is fully loaded or making sure the drawing procedure occurs only when the form is fully loaded?
HERES THE CODE:
Private Sub Form2_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Me.WindowState = FormWindowState.Maximized
Me.Show()
Application.DoEvents()
picturebox1.BackgroundImage = System.Drawing.Image.FromFile ("C:\test.bmp")
loadspots() ' Coordinates for the drawings
DrawBoxes()
End Sub
Private Sub DrawBoxes()
Me.Refresh()
Dim m As Short
PictureBox1.Refresh()
Dim Dg As System.Drawing.Graphics
Dim FT As New Font("Arial", 10, FontStyle.Bold)
Dg = PictureBox1.CreateGraphics
For m = 0 To 5
If LbY(m).Text <> "" Then
Dg.FillEllipse(Brushes.Red, CInt(lbX(m).Text) - 10, CInt(LbY(m).Text) - 10, 20, 20)
Dg.DrawString(Str(m + 1), FT, Brushes.Black, CInt(lbX(m).Text) - 8, CInt(LbY(m).Text) - 8)
Dg.FillEllipse(Brushes.Red, CInt(lbX(m).Text) - WhiteOff - 10, CInt(LbY(m).Text) - 10, 20, 20)
End If
Next m
Dg.Dispose()
End Sub
Any Help would be appreciated.