Odd GDI bug doublebuffering - Repost

S

Simon Tamman

Hi,

Re-posting this as the formatting on the other post is terrible.

If I inherit from a control with the following OnPaint override and draw in
the DoPaint method then i get odd UI results when a combobox is dropped down
on top of the control and then removed. I use this code in CE as well where
the problem is greater due to the loading circle and the volume control boxes
that pop-up.
This problem is reproducible on the desktop though. A full example is posted
afterwards for you to copy -> paste and see the issue yourself.

Any help would be appreciated as the code looks fine to me (am I an idiot?)

protected override void OnPaint(PaintEventArgs e)
{
if (e.ClipRectangle.Width > 0 && e.ClipRectangle.Height > 0)
{
using (m_BackBuffer = new Bitmap(e.ClipRectangle.Width,
e.ClipRectangle.Height))
{
using (m_BackGraphics = Graphics.FromImage(m_BackBuffer))
{
DoPaint(new PaintEventArgs(m_BackGraphics, e.ClipRectangle));
}
e.Graphics.DrawImage(m_BackBuffer, 0, 0);
}
}
}
 
S

Simon Tamman

Oh I should add that as this is CE code aimed at the Compact Framework 2.00,
SetStyles() isn't available to me as it isn't supported in CF 2.00. :'(
 
K

Kevin_E

The cliprect can be anywhere in the middle of the drawing area. This code
assumes that it always starts in the upper left hand corner. It is probably
easiest to always make the back buffer be the size of the control's window
rect and then just grab the clip-rect portion after rendering. Or you can
try an put more effort into setting up the Bitmap's DC's offsets so that
bitmap is positioned within the cliprect for the control. (But you can't
always control what happens for 'off-screen' drawing and just a little
coordinate wrapping can really mess things up)

I did something similar 17 years ago and remember having a particularly
difficult time getting this to work for combo-boxes, maybe something about
having a hard time identifying the actual window containing the drop down?
Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top