Solved

Suspend Redraw/Repaint while code is executed

Posted on 2009-07-12
6
1,409 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
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 85

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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
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 85

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 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