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开发者_C百科 doing wrong?
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
精彩评论