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.
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:
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):
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