471,325 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Odd GDI bug doublebuffering - Repost

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);
}
}
}

-------

Full example: http://www.nomorepasting.com/getpaste.php?pasteid=16435
(posted elsewhere to prevent the replies from getting too long)
Jun 27 '08 #1
4 1090
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. :'(
Jun 27 '08 #2
On Tue, 03 Jun 2008 11:16:00 -0700, Simon Tamman
<Si*********@discussions.microsoft.comwrote:
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.
This is almost certainly due to your incorrect use of ClipRectangle. See
my other reply for more details.
Jun 27 '08 #3
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.

"Simon Tamman" wrote:
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);
}
}
}

-------

Full example: http://www.nomorepasting.com/getpaste.php?pasteid=16435
(posted elsewhere to prevent the replies from getting too long)
Jun 27 '08 #4
Thank you so much Peter! :)
Have responded in the other thread:

http://www.microsoft.com/communities...2fsettings.xml
Jun 27 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Adam | last post: by
14 posts views Thread by Steve McLellan | last post: by
5 posts views Thread by Adrian Parker | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.