Odd GDI bug doublebuffering - Repost

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?U2ltb24gVGFtbWFu?=

    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(PaintEv entArgs e)
    {
    if (e.ClipRectangl e.Width 0 && e.ClipRectangle .Height 0)
    {
    using (m_BackBuffer = new Bitmap(e.ClipRe ctangle.Width,
    e.ClipRectangle .Height))
    {
    using (m_BackGraphics = Graphics.FromIm age(m_BackBuffe r))
    {
    DoPaint(new PaintEventArgs( m_BackGraphics, e.ClipRectangle ));
    }
    e.Graphics.Draw Image(m_BackBuf fer, 0, 0);
    }
    }
    }

    -------

    Full example: http://www.nomorepasting.com/getpaste.php?pasteid=16435
    (posted elsewhere to prevent the replies from getting too long)
  • =?Utf-8?B?U2ltb24gVGFtbWFu?=

    #2
    RE: Odd GDI bug doublebuffering - Repost

    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. :'(

    Comment

    • Peter Duniho

      #3
      Re: Odd GDI bug doublebuffering - Repost

      On Tue, 03 Jun 2008 11:16:00 -0700, Simon Tamman
      <SimonTamman@di scussions.micro soft.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.

      Comment

      • =?Utf-8?B?S2V2aW5fRQ==?=

        #4
        RE: Odd GDI bug doublebuffering - Repost

        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(PaintEv entArgs e)
        {
        if (e.ClipRectangl e.Width 0 && e.ClipRectangle .Height 0)
        {
        using (m_BackBuffer = new Bitmap(e.ClipRe ctangle.Width,
        e.ClipRectangle .Height))
        {
        using (m_BackGraphics = Graphics.FromIm age(m_BackBuffe r))
        {
        DoPaint(new PaintEventArgs( m_BackGraphics, e.ClipRectangle ));
        }
        e.Graphics.Draw Image(m_BackBuf fer, 0, 0);
        }
        }
        }
        >
        -------
        >
        Full example: http://www.nomorepasting.com/getpaste.php?pasteid=16435
        (posted elsewhere to prevent the replies from getting too long)

        Comment

        • =?Utf-8?B?U2ltb24gVGFtbWFu?=

          #5
          Re: Odd GDI bug doublebuffering - Repost

          Thank you so much Peter! :)
          Have responded in the other thread:


          Comment

          Working...