I have the following problem: I placed a splitter-control (not split-container) in my form and added 2 panels. The splitter works properly but when I move the splitter, it starts to flicker - the panels dont.
I get the same result with a Split-Container.
I tried this but nothing works
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.DoubleBuffered = true;
...
class XSplitter : Splitter
{
public XSplitter() : base()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.DoubleBuffered = true;
}
}
class XPanel : Panel
{
public XPanel() : base()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.DoubleBuffered = true;
}
}
I use Windows 8.1 and VS 2010
Thx for help!
Here are the steps to use this control:
Use NonFlickerSplitContainer object instead of SplitContainer object in your application.
Look at Splitter source code - http://referencesource.microsoft.com
Splitter draws on parents' (not own) device context, using GDI calls from outside of WM_PAINT:
so style setting does not have any effect.
When Splitter moves, it removes image from previous position before drawing at new place:
If the screen refreshes at this moment, you see flickering.
Windows Forms was developed at those years, when most people used CRT monitors, and halftone brushes (vide supra) looks smooth. These days some LCD monitors flicker even on static picture.
The solution is creating of solid brush instead of halftone one:
and redrawing only difference rectangle on moving:
See my solution at https://gist.github.com/ArtemAvramenko/e260420b86564cf13d2e