Calling events

Gluttard

Active member
Joined
Jan 9, 2008
Messages
44
Programming Experience
Beginner
I've been trying to figure this out for a while but I haven't been able to figure it out.
I want to draw a line using 'Form1 Events' and the Declaration 'Paint'

So I want this:
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
e.Graphics.DrawLine(Pens.Black, 0, 0, 100, 100)
End Sub

To happen when I click button1.

I've tried a whole bunch of things but none have worked. Thanks in advance guys. I can clarify further if you need it.
 
Me.Refresh() method, this is a combination of a full client area Invalidate (including all child controls) followed by Update. Which in the end causes the control to repaint (and Paint event happens)
Acutally Paint happens so many times that you will see the line anyway, but that was perhaps not the point or question?
 
oh thanks!
So I could set a variable like 'Ready' or something as 0 to begin with, and then in the 'Paint' Event I can say (after having ready = 1 by clicking the button),
If Ready = 1
e..Graphics.DrawLine(Pens.Black, 0, 0, 100, 100)
End if
And then Me.Refresh?
I'll give it a shot.
 
Hey thanks JohnH, I got it to work with this code:

VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Ready = 1
        Me.Refresh()
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        If Ready = 1 Then
            e.Graphics.DrawLine(Pens.Black, 0, 0, 500, 500)
            Ready = 0
        End If
    End Sub
Thanks for the quick response too!
 
Last edited by a moderator:
Back
Top