I have a SplitContainer which needs DoubleBuffer-ing on the whole control.
I've tried to accomplish this in the usual way by using the example from Hans Passant found here which usually works great.
using System.Windows.Forms;
class BufferedSplit : SplitContainer
{
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
}
Unfortunately this produces the weird side effect that if you're moving the splitter it no longer animates/updates until you release the mouse which makes it hard to tell whether you're actually re-sizing the control. I assume this is because all redrawing is now done off screen before being shown on the UI.
(This effect is easier to see if you set the whole SplitContainer back colour to something like grey, then set each individual panel to white so you can see the splitter clearly).
I tried double buffering just the two panels (using more Hans magic) and although this does seem to now show the splitter moving correctly I have a bunch of other flickering on my child controls.
public BufferedSplit()
{
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.OptimizedDoubleBuffer, true);
var objMethodInfo = typeof(Control).GetMethod("SetStyle", BindingFlags.NonPublic | BindingFlags.Instance);
var objArgs = new object[] { ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.OptimizedDoubleBuffer, true };
objMethodInfo.Invoke(Panel1, objArgs);
objMethodInfo.Invoke(Panel2, objArgs);
}
Can I double buffer the whole SplitContainer control and also have the splitter animate correctly when it is dragged?
WPF is not an option!