Answer» 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 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*
|