• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1433
  • Last Modified:

Suspend Redraw/Repaint while code is executed


I'm having a flicker problem. I want to resize a form by changing the .left and the .width properties. However, the form is drawing as soon as I change the .left properties, so you can see the screen flicker as it paints the control that is too large. Then the .width property is executed and everything looks fine.

I want to freeze the display until both lines of code are executed. I've tried form1.suspendlayout, and also tried List1.beginupdate and a few api's that i saw posted on EE.

Any ideas?

  • 3
  • 2
1 Solution
Try setting the "DoubleBuffered" property of your form to "True".

This should remove the flicker that you are seeing.
In addition to the above, you could wrap your processing code within the BeginUpdate and EndUpdate calls:
        ' Do stuff here.

Open in new window

Mike TomlinsonMiddle School Assistant TeacherCommented:
You can change the Location/Size at the same time using the SetBounds() method:

Something like:

    Me.SetBounds(25, 25, 500, 500)
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

The 'BeginUpdate' and 'EndUpdate' methods will only make a difference when adding/removing list items. They temporarily stop the control from being re-rendered whilst numerous items are being added and/or removed to a) improve performance, and b) remove flicker.

Using the 'SetBounds' method will certainly help reduce flicker because it performs all of the updates at the same time.

If you are dealing with multiple controls, then you will probably still benefit from using the double buffer feature. The double buffer will help remove flicker from all controls on your form.

If your program is strictly for Win32, then there are a couple of Win32 specific functions that you can call to prevent a window from being redrawn by the OS until you are ready. You can use these functions in a similar way to the "BeginUpdate" and "EndUpdate" functions.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Yes...if you can't anything else to work for you then use WM_SETREDRAW with SendMessage:
Private Const WM_SETREDRAW As Integer= &HB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal handle As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Sub Foo()
    SendMessage Me.Handle, WM_SETREDRAW, False, 0 ' Turn OFF updates
    ' ...do something in here...
    SendMessage Me.Handle, WM_SETREDRAW, True, 0 ' Turn ON updates
End Sub

Open in new window

DanJournoAuthor Commented:
Out of all posts, this was the best and most complete solution. Many thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now