Controls flickering due to background image of panel
-
1. března 2012 10:03
Hello,
I have developed a windows application whose interface has multiple picture boxes panels with background images for rich look and also a usercontrol which contains a gridview and WPF scrollbar in an element host. All these controls are placed in one panel (this is also having a background image) which is equal to the size of windows form. The reason for placing all these controls in the panel is that the window can be resized, if needed, allowing scrollbars.
Due to these large number of controls in which some of them have transparent backgrounds loaded in a large panel having background image, the window is flickering when moved or any other application's window is moved over it.
I need suggestions regarding the ways to minimize this flickering.
Thanks in advance,
Surya
Surya Praveen
Všechny reakce
-
6. března 2012 5:22ModerátorHi Surya,
Flickering is a common issue in WinForm and I think you may need to try nobugz’s suggestion.
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/aaed00ce-4bc9-424e-8c05-c30213171c2c
The first one is enabling double-buffering by calling Control.SetStyle Method, see http://msdn.microsoft.com/en-us/library/system.windows.forms.control.setstyle.aspx
http://www.codeproject.com/Articles/12870/Don-t-Flicker-Double-Buffer
The second one is turned on WS_EX_COMPOSITED, it will Paints all descendants of a window in bottom-to-top painting order using double-buffering.
You may also try turn off the WS_CLIPCHILDREN style flag, it will excludes the area occupied by child windows when drawing occurs within the parent window.
For more details, see http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ff700543(v=vs.85).aspx
http://stackoverflow.com/questions/2612487/how-to-fix-the-flickering-in-user-controls
Since you have the controls' background set to "Transparent", you may also read the link below http://stackoverflow.com/questions/4690426/why-do-my-winforms-controls-flicker-and-resize-slowly
In addition, I’m not sure if WPF scrollbar and GridView(Do you mean the GridView in ASP.NET?), but you might try use TrackBar and DataGridView instead.
Please let me know the result.
Best Regards,
Bob Wu [MSFT]
MSDN Community Support | Feedback to us
- Upravený Bob Wu-MTMicrosoft Contingent Staff, Moderator 6. března 2012 5:22 edit links
-
6. března 2012 9:37
Hello Bob,
Thanks for your answers and links.
I have already tried nobugz's suggestion turning on WS_EX_COMPOSITED. But it is fine with windows controls, but the WPF scrollbar is not visible after turning this ON and instead black holes are visible in their place. Nobugz in his blog said that this doesnot work for third-party controls. May be this is also true regarding WPF scrollbar which is shown using ElementHost control.
I need WPF scrollbar as in our design for client application, the scrollbar is having custom look that matches to the background of form.
I did not try setting WS_CLIPCHILDREN flag. How and where to set this flag? Please suggest me.
Surya Praveen
-
6. března 2012 9:50Moderátor
Hi Surya,
So, turning on WS_EX_COMPOSITED will solve this issue but making the scrollbar unvisible, am I right?
Well, I think you might try custom drawing TrackBar instead of scrollbar.
WS_CLIPCHILDREN is similar to WS_EX_COMPOSITED, just overwriting CreateParams.
You can find more details in this link,http://stackoverflow.com/questions/2612487/how-to-fix-the-flickering-in-user-controls.
Best Regards,
Bob Wu [MSFT]
MSDN Community Support | Feedback to us
- Označen jako odpověď Surya Praveen 7. března 2012 10:33
-
7. března 2012 5:08
Hi Bob,
Turning off the window's style WS_CLIPCHILDREN worked extremely great!!! This removed ugly patches left over by child controls.
I thank you so much for providing all available links on this issue!!!
Thanks to nobugz for his clear and detailed suggestions in the link http://stackoverflow.com/questions/2612487/how-to-fix-the-flickering-in-user-controls. One more suggestion that worked well suggested in the link is using background images of exact control's size and using pixel format Format32bppPArgb.
I am still using WPF controls - scrollbars and textboxes which are still flickering but at an ignorable level (I don't think we can stylize a track bar as flexible as WPF scrollbar). I feel that the extended style WS_EX_COMPOSITED is not all a good solution when using WPF controls. Even if WPF controls are not present, this style takes lot of CPU's cost and black patches are visible around borders.
I just want to list out solutions that fixed flickering issues in my application:
1. Using a custom panel on which double buffering is enabled and WS_CLIPCHILDREN is turned off
2. Setting DoubleBuffered property to True on windows form and all user controls (Do not turn off WS_CLIPCHILDREN if WPF control is present in user control, this makes redraw problems of WPF control)
3. Using background images of exact sizes (by writing a method for shrinking image) for controls and using pixel format "Format32bppPArgb".
Surya Praveen
- Upravený Surya Praveen 7. března 2012 5:12
- Označen jako odpověď Surya Praveen 7. března 2012 10:33
-
7. března 2012 8:34ModerátorHi Surya,
I glad to hear that it works and thank you for sharing your solution with us.
Have a nice day.Bob Wu [MSFT]
MSDN Community Support | Feedback to us