Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Suspend Redraw/Repaint while code is executed

Posted on 2009-07-12
6
Medium Priority
?
1,430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 13

Expert Comment

by:numberkruncher
ID: 24834481
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
ID: 24834486
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 86

Expert Comment

by:Mike Tomlinson
ID: 24834724
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 13

Expert Comment

by:numberkruncher
ID: 24834769
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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 24834795
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
ID: 31602568
Out of all posts, this was the best and most complete solution. Many thanks.
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

604 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