Solved

Suspend Redraw/Repaint while code is executed

Posted on 2009-07-12
6
1,416 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 500 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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