JavaScript Editor JavaScript Editor     JavaScript Debugger

Previous Section Next Section

Main Page

Repainting Windows

When you draw graphics in a form and then minimize and then restore the form, or cover and then uncover it, you need to redraw the graphics as well. (As mentioned in the In Depth section, you didn't have to do so in VB6 and earlier, where forms supported the AutoRedraw property, but now you do because that property no longer exists.) You can do that in the form's Paint event handler, which is called when the form needs to be drawn or painted. As an example, I can redraw the most recent graphics figure in the Painter example this way, using the Paint event:

    Private Sub Form1_Paint(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.PaintEventArgs) _
            Handles MyBase.Paint
        Select Case Tool
            Case Tools.Rectangle
                g.DrawRectangle(Pens.BlueViolet, r)
            Case Tools.Ellipse
                g.DrawEllipse(Pens.BlueViolet, r)
            Case Tools.Line
                g.DrawLine(Pens.BlueViolet, up, down)
            Case Tools.Draw
                If NumberPoints >= 2 Then
                    g.DrawLines(Pens.BlueViolet, Points)
                End If
        End Select
    End Sub

Now when you minimize and then restore Painter, the most recent figure reappears (to redraw all the figures the user has drawn, you can store their dimensions and types and redraw them all one by one, of course).

Previous Section Next Section

JavaScript Editor Free JavaScript Editor     JavaScript Editor