Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: (VB) Call Form1_Paint after Form1_Load has been called.  (Read 10804 times)

0 Members and 1 Guest are viewing this topic.

liambiscuit

    Topic Starter


    Hopeful

    (VB) Call Form1_Paint after Form1_Load has been called.
    « on: March 16, 2009, 07:35:25 PM »
    I think the title is self-explanatory, but here's some extra:

    What I am trying to do is so that whenever the end of Form1_Click is reached, Form1_Paint is called.
    Code: [Select]
    Form1_Paint(sender,e)Returns error: Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.PaintEventArgs'.
    Which is what I anticipated.

    If I put this:
    Code: [Select]
            Dim p As System.Windows.Forms.PaintEventArgs
            Form1_Paint(Me, p)
    I am given the warning that 'p' is used before defined (It never IS defined) and later on, when trying to draw a rectangle in form1_paint: Object reference not set to an instance of an object.

    So how do I either define 'p' or call form1_paint without causing error later on?

    Here is my whole code (Not that long, not that complicated, promise :: the three lines of '' 's is where the errors occur):

    Code: [Select]
    Public Class Form1
        Public elist As New List(Of Point)
        Public txt As Integer
        Public dot As Image = Image.FromFile(Application.StartupPath & "\data\dot.png")

        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Form1_Click(sender, e)
        End Sub

        Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
            elist.Add(New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y))
            elist.Add(New Point(Windows.Forms.Cursor.Position.X, Windows.Forms.Cursor.Position.Y))
            ''
            ''HERE IS WHERE FORM1_PAINT IS CALLED
            ''
        End Sub

        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            If Not elist.Count = 0 Then
                For Each point In elist
                    Dim rect As Rectangle = New Rectangle(point.X - 5, point.Y - 5, 10, 10)
                    e.Graphics.DrawRectangle(Pens.Orange, rect)
                    ''
                    '' THe above line is where an error is caught when using "form1_paint(me, p)"
                    ''
                Next
            End If
        End Sub
    End Class
    " When the rich wage war its the Poor who die "
            Linkin Park



    Whoever said that nothing is impossible has obviously never tried to slam a revolving door. -- Lauren

    You cannot buy your friends but you can buy them pizza - AzureBlade49

    liambiscuit

      Topic Starter


      Hopeful

      Re: (VB) Call Form1_Paint after Form1_Load has been called.
      « Reply #1 on: March 16, 2009, 07:52:24 PM »
      Mother f....

      I hate google.

      Hate it.

      Yahoo FTW.

      The first 30 minutes of googling, no success.

      Two minutes after posting, i learn 'Invalidate()'

      Calls all the *_paint functions as soon as your GPU can handle it. and my ATI Radeon 3200 can draw a box almost instantly.

      *sigh*

      Remove the thread, admin. Or leave this for other morons like myself.

      *sigh*
      " When the rich wage war its the Poor who die "
              Linkin Park



      Whoever said that nothing is impossible has obviously never tried to slam a revolving door. -- Lauren

      You cannot buy your friends but you can buy them pizza - AzureBlade49