StrataFrame Forum

Remedy for Form Flicker

http://forum.strataframe.net/Topic4832.aspx

By Brad Vick - 11/28/2006





I have spent quit a bit of time searching for a remedy for our form flickering issue. On some of our busy forms (80-100 controls) when the form is drawing you can see the individual controls being drawn, which causes the form to flicker. What I want to happen is basically draw the form invisibly, then once all the forms are drawn show the entire form. I have attempted the doublebuffer solution but it has not helped the situation.



Has anyone else experienced this 'flicker'? If so how did you remedy it?
By StrataFrame Team - 11/28/2006

Yes, we have experienced it... and the only solution we have found was to places sets of controls on separate tabs on the page.  The DoubleBuffer property on the form didn't do anything for us, either, and there is no way to completely lock a form and prevent drawing or to force the form to only draw one time.  Anyone else have a suggestion?
By Brad Vick - 11/28/2006





We try not to use tabs, instead we are using the panel manager and breaking the controls down inside individual panels.



Any ideas?
By Ross L Rooker, Sr. - 10/31/2007

Is the flicker issue resolved in the framework when using tabbed forms?
By Ben Hayat - 10/31/2007

What I want to happen is basically draw the form invisibly, then once all the forms are drawn show the entire form.


You may want to set the Opacity=0 or .25 first and then when all controls are drawn, you can set to 1 through a loop to give it a nice effect.
By Greg McGuffey - 10/31/2007

Good to see back on the forum, ben!
By StrataFrame Team - 11/1/2007

With the way that .NET uses controls that are individually windowed (each control is considered to be its own window wth its own hWnd), the drawing issues at form startup are hard to avoid.  There are some workarounds, but nothing that is simple:

1)  Show the form somewhere off screen (like (10000, 10000) and once the SetVisibleCore has existed (or once the Shown event fires), the move its location back to the screen

2)  For panels, show the panel off screen, once it's done rendering, use the Control.DrawToBitmap() method to take a snapshot of the panel, show a picture box in place of the panel with the picture, relocate the panel to slide it underneath the picture, and lastly, hide the picture.

There are other ways, but thinks like WM_SETREDRAW and LockWindow only work for one window handle at a time, and only affect the form, not all controls on the form.

The second option is what we ended up having to do for PracticeStudio.NET because the way our interface works, it doesn't have forms, just pages that open up as tabs.

By StrataFrame Team - 11/1/2007

You'd think for a $1 billion project like .NET 2.0 with 700 programmers, they'd come up with a way to prevent the flicker when forms load... oh well.
By Jc Martinez - 11/1/2007

Hi Guys,

Since I’m new to .Net and strataframe I tend to read as many post to see what issues people are having and how they are handled. This one caught my attention in its absurdity Crazy that like Ben points out should not exists and after searching for this issue it seems to be a grieving complaint Angry among .net developers.

In any case its resolution is a little above my head Hehe but besides the solutions before mentioned I found these 2 post that might help others.

Frozen forms for flickering-free updates
http://www.dotnet2themax.com/blogs/fbalena/PermaLink,guid,6336502b-57c5-430d-9d37-7f9be484f6b3.aspx

Practical Tips for Boosting the Performance of Windows Forms Apps
http://msdn.microsoft.com/msdnmag/issues/06/03/WindowsFormsPerformance/

By Ross L Rooker, Sr. - 11/1/2007

Unfortunately it is not just when a form loads. After my form is loaded, clicking on any tab, then back repeatedly, shows the ghost image of the tab clicked from while drawing the control on the page tab clicked to. If it was just on the page load it wouldn't be as bad. My thought would be a lock to the windows 32 desktop on the activation of the page tab and then unlocking after the tab is rendered. Is there any example of the win32 api code required to handle this and what event it should be located in?
By Trent L. Taylor - 11/5/2007

We actually added this API call to the SF tools namespace.  It will be included in the 1.6.2 build or you could just manually call the API.

Using SF

MicroFour.StrataFrame.Tools.LockScreen.Lock(Me)
MicroFour.StrataFrame.Tools.LockScreen.Unlock()

Using WinAPI Directly (All the SF method does)

<DllImport("user32.dll")> _
Private Shared Function LockWindowUpdate(ByVal hWndLock As IntPtr) As Boolean
End Function

'-- Lock the window
LockWindowUpdate(Me.Handle)

'-- Unlock the Window
LockWindowUpdate(Intptr.Zero)