Results 1 to 27 of 27

Thread: Stop RectangleShape flickering on form resizing?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Stop RectangleShape flickering on form resizing?

    I've a form where I add a panel1 control to add 3D borderstyle
    In that panel I add a RectangleShape1 control.

    The problem is when resizing the form the RectangleShape flicks a lot. Even if the rectangleshape is not resized when the forms resizes.

    I've read some solutions that works for some people. I've applied the solution, but the rectangleshape still flicks.

    The people recommend to set some flags to true:
    SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
    SetStyle(ControlStyles.ResizeRedraw, True)
    SetStyle(ControlStyles.UserPaint, True)
    SetStyle(ControlStyles.AllPaintingInWmPaint, True)
    SetStyle(ControlStyles.SupportsTransparentBackColor, True)


    And set Me.DoubleBuffered = true

    I've tried the solutions running the application in vs and running from the *.exe file and it still flicks.

  2. #2
    New Member
    Join Date
    Nov 2013
    Posts
    15

    Re: Stop RectangleShape flickering on form resizing?

    I found this solution:
    http://stackoverflow.com/a/7759951

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Stop RectangleShape flickering on form resizing?

    Don't forget also that you can always draw the rectangle yourself; it's not like a rectangle is a difficult item to draw considering that there is a built in method for drawing one. But in your specific case and if you are dead set on using the RectangleShape, using the SuspendLayout method like rrosskopf linked to should suffice.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by rrosskopf View Post
    I found this solution:
    http://stackoverflow.com/a/7759951
    Thanks it works, but it doesn't update the graphics while resizing. I forgot to mention that the graphics need be updated while the form is resized.
    I've been reading more documentation and some users suggest to stop using shape or line controls because it's imposible to stop 100% flickering. So a guy recommends to use Win32 API drawing methods
    source:http://forums.devx.com/showthread.ph...shape-controls

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by Jose_VB View Post
    So a guy recommends to use Win32 API drawing methods
    source:http://forums.devx.com/showthread.ph...shape-controls
    Or just draw the rectangle using the Graphics.DrawRectangle method.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Stop RectangleShape flickering on form resizing?

    Looking back over your past threads there is a trend: You are consistently fighting against using the proper tools for the job. I have no love for graphics programming, because I suck at graphics to begin with, but I've done some fairly complex interfaces using graphics at least as complex as you appear to be going with (rectangles, lines, selectable and moveable regions, some circles, and so forth). There is a right way to do it and a hard way to do it (actually, there are a couple right ways these days, but it's easiest to stick with GDI). The right way is to do all your drawing in the Paint event handler. The hard way is everything else.

    In the past, you have suggested that you tried that, but that perhaps something didn't work right. It's the right way to go, and would eliminate these issues you are having, so perhaps it is time to figure out what went wrong when you followed the appropriate approach.
    My usual boring signature: Nothing

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by dday9 View Post
    Or just draw the rectangle using the Graphics.DrawRectangle method.
    I'm working with that method and it works much better.

    Quote Originally Posted by Shaggy Hiker View Post
    Looking back over your past threads there is a trend: You are consistently fighting against using the proper tools for the job. I have no love for graphics programming, because I suck at graphics to begin with, but I've done some fairly complex interfaces using graphics at least as complex as you appear to be going with (rectangles, lines, selectable and moveable regions, some circles, and so forth). There is a right way to do it and a hard way to do it (actually, there are a couple right ways these days, but it's easiest to stick with GDI). The right way is to do all your drawing in the Paint event handler. The hard way is everything else.

    In the past, you have suggested that you tried that, but that perhaps something didn't work right. It's the right way to go, and would eliminate these issues you are having, so perhaps it is time to figure out what went wrong when you followed the appropriate approach.
    Yes, it worked but I was working with different options and I've introduced new code in the program. At the moment the best way is the way you've been recommending me for some time: writting the code in the Paint event. It works great. But using Graphics.DrawRectangle makes more complex the code for other tasks I want to introduce. So for that reason I tried again with RectangleShape.

    At the moment, I'm resizing the form using Graphics.DrawRectangle and the rectangle doesn't flicks.
    The actual question is how to erase the older rectangles (DrawRectangle) when I resize the form. I remember that I've done it before and I'm searching between the other vb solution code.

    Me.Refresh, Me.Dispose or something similar I think the code is.

  8. #8
    New Member
    Join Date
    Nov 2013
    Posts
    15

    Re: Stop RectangleShape flickering on form resizing?

    If you override the resize events, can't you make them do anything you want them to do? I know it's a lot of work, but...

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by Jose_VB View Post
    At the moment, I'm resizing the form using Graphics.DrawRectangle and the rectangle doesn't flicks.
    The actual question is how to erase the older rectangles (DrawRectangle) when I resize the form. I remember that I've done it before and I'm searching between the other vb solution code.

    Me.Refresh, Me.Dispose or something similar I think the code is.
    It's best to override the OnPaint event. This not only updates the form immediately during runtime, but also during design time too. To override the OnPaint, start typing Protected Overrides Sub OnPaint and chose the event the intellesence provides. Here is how it'd look completely generated:

    Code:
        Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
        End Sub
    You'd use the OnPaint event the same that you'd use the regular Paint event. Just call e.Graphics.DrawRectangle...
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by rrosskopf View Post
    If you override the resize events, can't you make them do anything you want them to do? I know it's a lot of work, but...
    I don't fully understand the solution you're explaining. I think you want to say
    Code:
      Protected Overrides Sub OnResize(e As System.EventArgs)
            MyBase.OnResize(e)
        End Sub
    Quote Originally Posted by dday9 View Post
    It's best to override the OnPaint event. This not only updates the form immediately during runtime, but also during design time too. To override the OnPaint, start typing Protected Overrides Sub OnPaint and chose the event the intellesence provides. Here is how it'd look completely generated:

    Code:
        Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
        End Sub
    You'd use the OnPaint event the same that you'd use the regular Paint event. Just call e.Graphics.DrawRectangle...
    I've changed the code from
    Code:
        Private Sub CotizacionesFRM2_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
           
            Me.CreateGraphics.DrawRectangle(MyPencil, 15, 15, Me.Width - 100, Me.Height - 100)
    
        End Sub
    to
    Code:
        Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
    
            MyBase.OnPaint(e)
            Me.CreateGraphics.DrawRectangle(MyPencil, 15, 15, Me.Width - 100, Me.Height - 100)
            
        End Sub
    And now the rectangle is bigger when I resize (to big) the form, but it doesn't happens the same when I make the form smaller. The rectangle doesn't becomes smaller when I decrease the size of the form.

  11. #11
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Stop RectangleShape flickering on form resizing?

    Not Me.CreateGraphics.DrawRectangle, e.Graphics.DrawRectangle. The way you have it, you are adding the overhead and resource consumption of creating a non-trivial graphics object. There is already a graphics object created and managed by the form, which is supplied as part of the e argument to the paint method. Use the one provided, and don't create your own.
    My usual boring signature: Nothing

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by Shaggy Hiker View Post
    Not Me.CreateGraphics.DrawRectangle, e.Graphics.DrawRectangle. The way you have it, you are adding the overhead and resource consumption of creating a non-trivial graphics object. There is already a graphics object created and managed by the form, which is supplied as part of the e argument to the paint method. Use the one provided, and don't create your own.
    Code:
        Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
    
            MyBase.OnPaint(e)
            e.Graphics.DrawRectangle(MyPencil, 15, 15, Me.Width - 100, Me.Height - 100)
         
        End Sub
    The rectangle doesn't resize when the form is resized.

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Stop RectangleShape flickering on form resizing?

    1) Put a breakpoint on either of the lines in the method.
    2) Resize the form.

    Is the breakpoint hit? It it is, take a look at Me.Width and Me.Height. If you do this a couple times, you will see a pattern that will probably explain what is happening, except that I think it is more likely that the breakpoint isn't being hit.

    The call to MyBase.OnPaint(e) doesn't seem like it would be the culprit, but it might be. You probably don't need that line, so comment it out and try that.
    My usual boring signature: Nothing

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by Shaggy Hiker View Post
    1) Put a breakpoint on either of the lines in the method.
    2) Resize the form.

    Is the breakpoint hit? It it is, take a look at Me.Width and Me.Height. If you do this a couple times, you will see a pattern that will probably explain what is happening, except that I think it is more likely that the breakpoint isn't being hit.

    The call to MyBase.OnPaint(e) doesn't seem like it would be the culprit, but it might be. You probably don't need that line, so comment it out and try that.
    1. Breakpoint MyBase.OnPaint(e) only
    - The program loads but just after the form loads the program is interrupted in that point (breakpoint) so I cannot access to the form

    2. Breakpoint in e.Graphics.DrawRectangle(MyPencil, 15, 15, Me.Width - 100, Me.Height - 100) only while MyBase.OnPaint(e) is not commented out
    - The same as in 1

    3. Breakpoint in e.Graphics.DrawRectangle(MyPencil, 15, 15, Me.Width - 100, Me.Height - 100) while MyBase.OnPaint(e) is commented out
    - The same as in 1 and 2

  15. #15
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Stop RectangleShape flickering on form resizing?

    Right. That is one of the annoying things about debugging Paint event issues: The Paint event gets triggered a fair amount, and sometimes in awkward places. I should have mentioned that you can't add the breakpoint until after the form is already displayed, or else you'll trip over the breakpoint when you don't want to.
    My usual boring signature: Nothing

  16. #16
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Stop RectangleShape flickering on form resizing?

    Hmm, I tried it out myself and was able to duplicate the problem. The size was being updated in the OnPaint event and it doesn't matter where the MyBase.OnPaint was called, which is odd.

    To get it to work correctly, I added invalidate in the SizeChange event and now it works flawlessly.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  17. #17
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Stop RectangleShape flickering on form resizing?

    So, was it not painting on the resize?

    Technically, it does make sense that a window can shrink in size without invalidating its rectangle. If there are a bunch of controls on it that are sizing, then they would have to paint, but the form could get away with doing no more than changing the clipping rectangle when it shrinks. That's what it sounds like it is doing, which I find rather interesting.

    Calling Invalidate or Refresh will cause the paint event to be raised (which means that they shouldn't be called in the Paint Event EVER). Refresh is harsher, and shouldn't be used in many cases. Invalidate would be the right way to go, and putting it in the resize event would be about right, too. I seem to remember dealing with this when re-positioning a bunch of controls. Simply moving them around didn't cause redraws in some circumstances, but I was using XNA for that, so it may have been totally different.
    My usual boring signature: Nothing

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by dday9 View Post
    Hmm, I tried it out myself and was able to duplicate the problem. The size was being updated in the OnPaint event and it doesn't matter where the MyBase.OnPaint was called, which is odd.

    To get it to work correctly, I added invalidate in the SizeChange event and now it works flawlessly.
    It works right now in both cases, when I increase the size of the form and when I decrease the size of the form.
    The only detail is that it still flicks. But I'm trying a solution.


    Quote Originally Posted by Shaggy Hiker View Post
    So, was it not painting on the resize?

    Technically, it does make sense that a window can shrink in size without invalidating its rectangle. If there are a bunch of controls on it that are sizing, then they would have to paint, but the form could get away with doing no more than changing the clipping rectangle when it shrinks. That's what it sounds like it is doing, which I find rather interesting.

    Calling Invalidate or Refresh will cause the paint event to be raised (which means that they shouldn't be called in the Paint Event EVER). Refresh is harsher, and shouldn't be used in many cases. Invalidate would be the right way to go, and putting it in the resize event would be about right, too. I seem to remember dealing with this when re-positioning a bunch of controls. Simply moving them around didn't cause redraws in some circumstances, but I was using XNA for that, so it may have been totally different.
    At the moment, when I introduce the next:
    Code:
     Private Sub FRM2_ClientSizeChanged(sender As Object, e As System.EventArgs) Handles Me.ClientSizeChanged
            Me.Invalidate()
        End Sub
    it works. But it still flicks. I'm introducing the doblebuffer and executing the exe to see if the flickering stops.

  19. #19

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Stop RectangleShape flickering on form resizing?

    It works as required. When I introduce Me.DoubleBuffered = True in Form_Load it work much more better than in all the other cases. I've also tried to see the improvements when I introduce the SetStyle that I've posted in the post #1 but there is not difference between using them and not using them.

  20. #20
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Stop RectangleShape flickering on form resizing?

    When you resize the form, as you noted, you don't get paint events for making the form smaller since what you see has already been painted.
    When you increase the size of the form, unfortunately for your case, and for anyone who wants to do something that will modify the form outside of the new area being exposed, the graphics object passed to you as e.graphics already has a clipping region set so it only has to draw in the newly exposed area of the form.
    Having the existing area of the form outside the clipping area speeds up the GDI+ drawing since GDI+ seems to be very efficient (compared to GDI) about not wasting time processing drawing commands that are outside the clipping region.
    But of course the drawback is, if your form is not fairly static and you're trying to update the whole form, i.e. remove a rectangle outside the part of the form that Windows thinks needs to be redrawn, your drawing is clipped so you end up with old garbage on your form.
    So, you have to resort to using invalidate to cause a second paint event with with the full bounds of the form writeable.
    You should be aware, that if you do an invalidate, and do your drawing in the Paint event, then you don't need to do anything specific to erase any previous drawing you done in past Paint events.
    When you get a paint event (for the full form), the Form has already been cleared of any previous drawing you've done in previous paint events, so you only need to redraw. (Unless you've set a ControlStyle option to prevent the form from giving you a clean slate).

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2012
    Posts
    290

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by passel View Post
    When you resize the form, as you noted, you don't get paint events for making the form smaller since what you see has already been painted.
    When you increase the size of the form, unfortunately for your case, and for anyone who wants to do something that will modify the form outside of the new area being exposed, the graphics object passed to you as e.graphics already has a clipping region set so it only has to draw in the newly exposed area of the form.
    Having the existing area of the form outside the clipping area speeds up the GDI+ drawing since GDI+ seems to be very efficient (compared to GDI) about not wasting time processing drawing commands that are outside the clipping region.
    But of course the drawback is, if your form is not fairly static and you're trying to update the whole form, i.e. remove a rectangle outside the part of the form that Windows thinks needs to be redrawn, your drawing is clipped so you end up with old garbage on your form.
    So, you have to resort to using invalidate to cause a second paint event with with the full bounds of the form writeable.
    You should be aware, that if you do an invalidate, and do your drawing in the Paint event, then you don't need to do anything specific to erase any previous drawing you done in past Paint events.
    When you get a paint event (for the full form), the Form has already been cleared of any previous drawing you've done in previous paint events, so you only need to redraw. (Unless you've set a ControlStyle option to prevent the form from giving you a clean slate).
    Exactly. Thanks for the information.

    One more question... once the rectangle has been drawn in the form and it works correctly, I want to ask about drawing it in a panel1 control. I add a panel control to have like a Sizable 3D borderstyle. As you know the rectangle has to be drawn in the panel1 control.

    Code:
        Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
    
            MyBase.OnPaint(e)
            e.Graphics.DrawRectangle(MyPencil, 15, 15, Me.Width - 100, Me.Height - 100)
      
        End Sub
    I thought to replace
    Code:
    e As System.Windows.Forms.PaintEventArgs
    by
    Code:
    e As System.Windows.Forms.Panel.PaintEventArgs
    but as you know the panel control has not the option PaintEventArgs

    The other option is to use Panel1.CreateGraphics.DrawRectangle(...) after the MyBase.OnPaint(e) but reading the posts it's not a very good idea to use that way of drawing the rectangle on Panel1.

  22. #22
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Stop RectangleShape flickering on form resizing?

    You can't override the OnPaint event like that. If you wanted to do what you're doing on a panel, you'd have to create a user control that inherits a panel and then override that control's OnPaint event inside that class. Something like this:

    Code:
    Public Class DoubleBufferedPanel
        Inherits Windows.Forms.Panel
    
        Private mypen As Pen
        Public Property Pen() As Pen
            Get
                Return mypen
            End Get
            Set(ByVal value As Pen)
                mypen = value
            End Set
        End Property
    
        Public Sub New()
            Me.DoubleBuffered = True
    
            SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.DoubleBuffer Or ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
    
            UpdateStyles()
        End Sub
    
        Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
    
            e.Graphics.DrawRectangle(mypen, New Rectangle(15, 15, Me.Parent.Width - 100, Me.Parent.Height - 100))
    
        End Sub
    
    End Class
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  23. #23
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Stop RectangleShape flickering on form resizing?

    Actually, it isn't all that complicated as that. What you need is a derived panel that has the DoubleBuffered property. For some reason, the DoubleBuffered property isn't public in the panel, even though it is derived from Control. I've never understood that decision. Still, what I have done to handle that is to create the program using a regular panel. The panel has a paint event, and every paint event gets a PaintEventArgs, so it has a Graphics object as part of the e argument. You do all your drawing in the paint event handler for the panel.

    Once you have it all working with the panel, you can EASILY change it over to a derived class that has the DoubleBuffered property set to True:

    Code:
    Public Class FlickerPanel
        Inherits Windows.Forms.Panel
    
        Public Sub New()
            Me.DoubleBuffered = True
        End Sub
    
    End Class
    That's all I have in my program to allow double buffering for a panel, but there is one step beyond this. You copy that code to somewhere reasonable (not inside any other class). Then go to the .designer.vb file for the form in question and look at the InitializeComponents method. There are two things you have to find in this method. The first is where the panel is declared, and the second is where the panel is created.

    The first will be right off in the method, and will look like this:

    Me.Panel1 = New System.Windows.Forms.Panel()

    you would change that to:

    Me.Label4 = New FlickerPanel

    Then, down at the bottom of the method you will find a line that looks like this:

    Friend WithEvents Panel1 As System.Windows.Forms.Panel

    which you change to:

    Friend WithEvents Panel1 As FlickerPanel

    That's it. You don't have to mess around with overriding the paint event. The whole point is to be using a panel that has the DoubleBuffered property set to True, which is all I am doing.
    My usual boring signature: Nothing

  24. #24
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by Shaggy Hiker View Post
    Actually, it isn't all that complicated as that. What you need is a derived panel that has the DoubleBuffered property. For some reason, the DoubleBuffered property isn't public in the panel, even though it is derived from Control. I've never understood that decision. Still, what I have done to handle that is to create the program using a regular panel. The panel has a paint event, and every paint event gets a PaintEventArgs, so it has a Graphics object as part of the e argument. You do all your drawing in the paint event handler for the panel.
    Painting a double-buffered control takes over twice as long as one which isn't. I think the idea of making it less easy for panels and the like is that container controls are meant to stay "lightweight" (i.e. not creating a painting overhead) so that you can place one container inside another to make more complex form layout. These controls are often meant to add a "behaviour" to the content such as scrolling a virtual space in a Panel or exclusively checking RadioButtons in a GroupBox. The idea has been worked out much better in WPF where it is a matter of course to put containers within containers practically ad infinitum as a way of adding behaviours to the content. The upshot is that most of the time people think of double-buffering a panel they might as well use a PictureBox instead, since it is double-buffered by default. A double-buffered panel might be useful in situations where you want a changing background image in combination with hosting and/or scrolling child controls.

    The SetStyles coding is of course superfluous because the DoubleBuffered property wraps that anyway.

    BB

  25. #25
    Member Gale_i's Avatar
    Join Date
    Nov 2013
    Posts
    52

    Re: Stop RectangleShape flickering on form resizing?

    Code:
      Public Sub Form1_ResizeBegin(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeBegin
    
          Me.SetStyle(ControlStyles.UserPaint Or ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.SupportsTransparentBackColor, True)
    
      End Sub
    
      Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
    
          Me.Update()
    
      End Sub
    This worked perfectly for me...

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

    Re: Stop RectangleShape flickering on form resizing?

    Quote Originally Posted by Shaggy Hiker View Post
    Right. That is one of the annoying things about debugging Paint event issues: The Paint event gets triggered a fair amount, and sometimes in awkward places. I should have mentioned that you can't add the breakpoint until after the form is already displayed, or else you'll trip over the breakpoint when you don't want to.
    A breakpoint doesn't necessarily need to break execution. Place the breakpoint in the method at a point where the variables you want to inspect will be available. Right-click on the breakpoint and in the context menu select "When Hit...". In the dialog that pops up, select the "Print a message" to enable that section, change the message format to include the variables you are interested in, and then make sure "Continue execution" is selected. This will then not halt the program (with all the problems associated with that in a paint handler) but it will output the message with your variable values to the Debug Output window in the IDE.

  27. #27
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: Stop RectangleShape flickering on form resizing?

    That's a good point. The default behavior of the breakpoint is the easiest to reach for, and could be made to work in this case, too, but it is not the ONLY option, and there are some debugging gems in looking at the options for both breakpoints and exception behavior in debugging.
    My usual boring signature: Nothing

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