I have a custom Control derived class for which I want to disable any automatic double buffering completely because I want to handle double buffering manually with a BufferedGraphics object. Drawing is done in OnPaint, Invalidate is called in MouseMove and Resize events for example.
However, if the Control is embedded into a Form with DockStyle.Fill, resizing the form (and subsequently the Control) seems to enable double buffering, no matter what I do. I can see no flicker although the drawing is fairly complex and causes a noticeable delay and the drawing result finally becomes visible.
On the other hand, if the Control is invalidated by a different event (MouseMove) or if I set DockStyle.None and manually resize it (test-wise by a Button), I see the flickering during the drawing process, from which I conclude that double buffering is disabled in this case.
I have ruled out that I am still double buffering with BufferedGraphics (have commented out this part and draw directly to PaintEventArgs.Graphics). Also, setting DoubleBuffered=false
or SetStyle(ControlStyles.OptimizedDoubleBuffer, false)
inside the constructors of Form and/or Control were not successful.
Leaving the default double buffering on in addition to my manual handling does not seem to make much of a difference performance-wise (probably because building the image in the buffer is much slower than transferring it to screen, even if its done twice). But the redundancy feels a little untidy.
So, how can I disable double buffering for a Resize event that is passed on from the Form to my Control?