Question : Make button click occur onload

How do i make the following code occur on load?  I moved the code into the form1_load area but it doesn't show up.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'define GDI+ context representing a form
        Dim GdiSurface As Graphics
        GdiSurface = Me.CreateGraphics

        'draw a thick curve
        Dim CurvePen As New Pen(Color.Plum, 30)
        Dim CurvePoints() As Point = {New Point(10, 100), New Point(50, 80), New Point(200, 200)}
        GdiSurface.DrawCurve(CurvePen, CurvePoints)

        'draw rectangle
        Dim RecPen As New Pen(Color.Crimson, 10) 'perimeter
        Dim RecBrush As New SolidBrush(Color.LightBlue) 'paint the body
        GdiSurface.DrawRectangle(RecPen, 10, 10, 200, 30)
        GdiSurface.FillRectangle(RecBrush, 10, 10, 200, 30)

        'Release GDI context
        GdiSurface.Dispose()

    End Sub

Answer : Make button click occur onload

The underlying problem is here:

    GdiSurface = Me.CreateGraphics

CreateGraphics() in this context creates a drawing surface that is TEMPORARY.  When the form refreshes itself the drawing will simply be erased...and this is likely at Form Load().

For a PERSISTENT drawing you need either:
(1) Use "e.Graphics" supplied in the Paint() event of the Form.
(2) Draw to a Bitmap() and set it as the background of the Form.
Random Solutions  
 
programming4us programming4us