Results 1 to 11 of 11

Thread: [RESOLVED] Control.Invalidate(Rectangle) invalidating the whole control?

  1. #1

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Resolved [RESOLVED] Control.Invalidate(Rectangle) invalidating the whole control?

    I might be blind, however it looks to me as if
    Code:
    With Rectangle
       .X = 0
       .Y = 0
       .Width = 0
       .Height = 0
    End With
    Control.Invalidated(Rectangle)
    will Invalidate the whole control. I was expecting it to invalidate only the Rectangle, i.e. nothing in this case.

    Can anybody help me on that.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,397

    Re: Control.Invalidate(Rectangle) invalidating the whole control?

    What is Rectangle, is it the PowerPack rectangle, some kind of custom class, etc. ?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Control.Invalidate(Rectangle) invalidating the whole control?

    Sorry, I was lazy, Rectangle is a System.Drawing.Rectangle.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Control.Invalidate(Rectangle) invalidating the whole control?

    I would guess it's just a Drawing.Rectangle.

    From what little I've seen, that should invalidate only part of a control. However, how did you determine that you are not triggering an invalidation of the entire control invadvertently? For example, do you know that you are getting only one Paint event?
    My usual boring signature: Nothing

  5. #5

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Control.Invalidate(Rectangle) invalidating the whole control?

    I did the the obvious test (which I should have done before posting)
    In identical situations I have following lines in the mouse_mouse routine.
    Code:
    picbox.Invalidate(New Rectangle(0,0,0,0))
    or
    Code:
    picbox.Invalidate(New Rectangle(0,0,10,10))
    In the first case, the mouse_move will cause a Paint of the whole picbox, in the second one only the Top-Left (10*10) will be painted.

    @Shaggy Hiker
    If you remember my lst Thread about GameLoop into anothzer thread, I had this weird behaviour when thew picbox got updated by moving the mouse over it. It looks like this is the real reason.
    Please don't count the houres of worthless searching!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  6. #6

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Control.Invalidate(Rectangle) invalidating the whole control?

    One other question on "do you know that you are getting only one Paint event?"

    Is there a way to log/trace/whatever all events?
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,397

    Re: Control.Invalidate(Rectangle) invalidating the whole control?

    I did not know that you could invalidate a certain area/region of a control, but that shows my ignorance. I should've looked up the acceptable parameters for the Invalidate method.

    What I think might be happening is that because you're setting the values of the rectangle to it's default values(0), it may be ignoring the rectangle all together and invalidating the control as if you only called Control.Invalidate(). That seems logical because think about it, what would be invalidated at (0, 0, 0, 0), sure the location is (0, 0) but the size is also (0, 0).
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  8. #8
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Control.Invalidate(Rectangle) invalidating the whole control?

    Seems pretty straight-forward behaviour, treating a zero-size rectangle as a null rectangle, and responding to that by invalidating the entire container. I mean, if you really wanted to invalidate a rectangle of zero-size, you could have just not called Invalidate(), amirite? In what situation would you end up trying to invalidate a zero-size rectangle anyway?

  9. #9
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Control.Invalidate(Rectangle) invalidating the whole control?

    Quote Originally Posted by Evil_Giraffe View Post
    Seems pretty straight-forward behaviour, treating a zero-size rectangle as a null rectangle, and responding to that by invalidating the entire container. I mean, if you really wanted to invalidate a rectangle of zero-size, you could have just not called Invalidate(), amirite? In what situation would you end up trying to invalidate a zero-size rectangle anyway?
    Absolutely correct!
    Code:
    Public Sub Invalidate(ByVal rc As Rectangle, ByVal invalidateChildren As Boolean)
        If rc.IsEmpty Then
            Me.Invalidate(invalidateChildren)
        ElseIf Me.IsHandleCreated Then
            If invalidateChildren Then
                Dim rcUpdate As RECT = RECT.FromXYWH(rc.X, rc.Y, rc.Width, rc.Height)
                SafeNativeMethods.RedrawWindow(New HandleRef(Me.window, Me.Handle), rcUpdate, NativeMethods.NullHandleRef, &H85)
            Else
                Dim rect As RECT = RECT.FromXYWH(rc.X, rc.Y, rc.Width, rc.Height)
                Using New MultithreadSafeCallScope
                    SafeNativeMethods.InvalidateRect(New HandleRef(Me.window, Me.Handle), rect, ((Me.controlStyle And ControlStyles.Opaque) <> ControlStyles.Opaque))
                End Using
            End If
            Me.NotifyInvalidate(rc)
        End If
    End Sub

  10. #10
    PowerPoster
    Join Date
    Oct 2010
    Posts
    2,141

    Re: Control.Invalidate(Rectangle) invalidating the whole control?

    Deleted double posting.
    Last edited by TnTinMN; Jun 5th, 2014 at 12:21 PM. Reason: double post

  11. #11

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Control.Invalidate(Rectangle) invalidating the whole control?

    Thanks for all the inputs.

    Now understand the "weird" behaviour I saw.

    On the question, why I would want to .Invalidate a zero size rectangle. I'm was starting of with a zero size rectangle in order to collect rectangles in from different possible (exclusive) situation.
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

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