What does exactly 'Invalidate' method of controls do?
Try the following code:
VB Code:
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
Static Dim secondclick As Boolean
Static mousepos1, mousepos2 As Point
If e.Button = MouseButtons.Left Then
Dim g As Graphics = Me.CreateGraphics
If secondclick = False Then
Me.Refresh() ' comment this line and try the next line to note the difference.
' Me.Invalidate()
mousepos1 = New Point(e.X, e.Y)
secondclick = True
Else
mousepos2 = New Point(e.X, e.Y)
secondclick = False
g.DrawLine(New Pen(Color.Black, 1), mousepos1.X, mousepos1.Y, mousepos2.X, mousepos2.Y)
End If
g.DrawLine(New Pen(Color.Black, 1), e.X, e.Y - 5, e.X, e.Y + 5)
g.DrawLine(New Pen(Color.Black, 1), e.X - 5, e.Y, e.X + 5, e.Y)
g.Dispose()
End If
End Sub
How can you describe this difference between Refresh and Invalidate? Doesn't Refresh call Invalidate?