Solved

Suspend Redraw/Repaint while code is executed

Posted on 2009-07-12
6
1,387 Views
Last Modified: 2013-11-26
Hi,

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?

Thanks
Dan
0
Comment
Question by:DanJourno
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:numberkruncher
Comment Utility
Try setting the "DoubleBuffered" property of your form to "True".

This should remove the flicker that you are seeing.
0
 
LVL 13

Expert Comment

by:numberkruncher
Comment Utility
In addition to the above, you could wrap your processing code within the BeginUpdate and EndUpdate calls:
        ListBox1.BeginUpdate()
 

        ' Do stuff here.
 

        ListBox1.EndUpdate()

Open in new window

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
You can change the Location/Size at the same time using the SetBounds() method:
http://msdn.microsoft.com/en-us/library/z0tayb1b.aspx

Something like:

    Me.SetBounds(25, 25, 500, 500)
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 13

Expert Comment

by:numberkruncher
Comment Utility
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.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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

    Me.Refresh()

End Sub

Open in new window

0
 
LVL 5

Author Closing Comment

by:DanJourno
Comment Utility
Out of all posts, this was the best and most complete solution. Many thanks.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now