views:

455

answers:

1

I'm trying to write a panel in CF.NET that allows me to scroll the contents inside without flickering. I thought I'd try having a WrapperPanel class that contains another panel with the actual contents. Then I'd bitblt the contents of the interior panel to the wrapper based on the scrolling position.

But the bitblt isn't working for me. It's just leaving the destination surface as it was, with no visible change.

Here's the relevant code:

protected override void OnPaint(PaintEventArgs e)
{
    //Generate a proper-sized bitmap
    using (Bitmap bmp = new Bitmap(ClientSize.Width, ClientSize.Height))
    {
        using (Graphics bgr = Graphics.FromImage(bmp))
        {
            //bitblt from interior panel to that bitmap
            var srcDC = GetDC(_interiorPanel.Handle);
            var bmDC = bgr.GetHdc();
            var res = BitBlt(bmDC, 0, YOffSet, Width, Height, srcDC, 0, 0, 0x00CC0020);
            System.Diagnostics.Debug.WriteLine(res);
            ReleaseDC(_interiorPanel.Handle, srcDC);
            bgr.ReleaseHdc(bmDC);
        }
        //Draw that bitmap to this panel
        e.Graphics.DrawImage(bmp, 0, 0);
    }

    base.OnPaint(e);
}

Both the GetDC() and GetHdc() calls return a value, so at least they aren't failing. But that's about the extent of my troubleshooting knowledge with GDI+. Can someone see what I'm doing wrong?

A: 

Is the interior panel invisible? off screen? or what? The only way you'll get relevant data from it's HDC is when it's been painted via the normal message pump, which is not gonna happen if it's hidden or off screen, or if you manually paint it, which you obviously aren't doing.

This is a great resource for learning about flicker free Win32: http://www.catch22.net/tuts/flicker

Johann Gerell
Ok, so it's blank because the interior panel isn't really visible. But the link isn't going to help me much with fixing the problem. Is there a way to "manually paint" the interior panel once and use it for the bitblt? I want to fill a panel with items (that might be larger than the screen itself, then allow the user to drag up/down to view the contents. If I just put a panel inside a panel and move the interiorpanel, it flickers.
Jake Stevenson
No, you cannot explicitly do that. Have you tried inheriting a panel and overriding OnPaintBackground and OnPaint? Sounds to me like you actually want a custom control.
Johann Gerell
The screen layout has a dozen or so labels, some linklabels, and an image. So a panel seemed like the easiest way to go. But so far, nothing I do allows me to smooth-scroll it. It looks like I might have to just generate a static bitmap and drawtext and images on it, then use that :/
Jake Stevenson