Solved

Suspend Redraw/Repaint while code is executed

Posted on 2009-07-12
6
1,396 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
DevOps Toolchain Recommendations

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

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 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

21 Experts available now in Live!

Get 1:1 Help Now