BigSprout,
I think you are getting a bit confused by the graphics.
Let’s look at some fundamentals...
This code draws a rectangle on a form:
Code:
Private Sub bDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bDraw.Click Dim Graph As Graphics = Me.CreateGraphics 'The graphics object Graph.DrawRectangle(Pens.Blue, 20, 10, 200, 300) 'Draw the rectangle End Sub
There you have it. But ......
The drawing is very fragile. If you put something in front of it on the desktop, it will erase.
To overcome this problem, graphics are typically drawn from within a form’s Paint event. This event fires whenever the form is required to be redrawn. If you put a Beep() statement in the Paint event handler and rearrange your Desktop a bit you will see what I mean.
So alternatively we can draw the rectangle from within the Paint event like this:
Code:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint e.Graphics.DrawRectangle(Pens.Blue, 20, 10, 200, 300) 'Draw the rectangle End Sub
So that’s what the Paint event is for. Personally I find this quite dumb, but there is a better way using buffered graphics. We might have a look at this in a future step.


), I added this on Form2:
Leave a comment: