Results 1 to 3 of 3

Thread: What does exactly 'Invalidate' method of controls do?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474

    What does exactly 'Invalidate' method of controls do?

    Try the following code:
    VB Code:
    1. Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
    2.         Static Dim secondclick As Boolean
    3.         Static mousepos1, mousepos2 As Point
    4.         If e.Button = MouseButtons.Left Then
    5.             Dim  g As Graphics = Me.CreateGraphics
    6.             If secondclick = False Then
    7.                 Me.Refresh() ' comment this line and try the next line to note the difference.
    8.                 ' Me.Invalidate()
    9.                 mousepos1 = New Point(e.X, e.Y)
    10.                 secondclick = True
    11.             Else
    12.                 mousepos2 = New Point(e.X, e.Y)
    13.                 secondclick = False
    14.                 g.DrawLine(New Pen(Color.Black, 1), mousepos1.X, mousepos1.Y, mousepos2.X, mousepos2.Y)
    15.           End If
    16.             g.DrawLine(New Pen(Color.Black, 1), e.X, e.Y - 5, e.X, e.Y + 5)
    17.             g.DrawLine(New Pen(Color.Black, 1), e.X - 5, e.Y, e.X + 5, e.Y)
    18.             g.Dispose()
    19.         End If
    20. End Sub

    How can you describe this difference between Refresh and Invalidate? Doesn't Refresh call Invalidate?
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    Me.Invalidate() forces a Re-Paint
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Originally posted by dynamic_sysop
    Me.Invalidate() forces a Re-Paint
    Refresh: Forces the control to invalidate its client area and immediately redraw itself and any child controls.

    Invalidate: Invalidates a specific region of the control (adds it to the control's update region, which is the area that will be repainted at the next paint operation) and causes a paint message to be sent to the control.

    I think i am getting close to the difference but it is not still clear.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width