void AnimateScroll(int From, int To)
{
if (currentBandIndex == -1 || bands.Count == 0)
return;
//OutlookBarBand band = bands[currentBandIndex];
// Make sure we are whithin bounds
Debug.Assert(From >= 0 && From < bands.Count);
Debug.Assert(To >= 0 && To < bands.Count);
// Get needed dimensions
Rectangle viewPortRect = GetViewPortRect();
Rectangle headerRect = new Rectangle(0, 0, viewPortRect.Width, BAND_HEADER_HEIGHT);
Rectangle drawingRect = new Rectangle(0, 0, viewPortRect.Width, viewPortRect.Height + headerRect.Height * 2);
// Use straight GDI to do the drawing
IntPtr hDC = WindowsAPI.GetDC(Handle);
IntPtr hDCFrom = WindowsAPI.CreateCompatibleDC(hDC);
IntPtr hDCTo = WindowsAPI.CreateCompatibleDC(hDC);
IntPtr bmFrom = WindowsAPI.CreateCompatibleBitmap(hDC, drawingRect.Width, drawingRect.Height);
IntPtr bmTo = WindowsAPI.CreateCompatibleBitmap(hDC, drawingRect.Width, drawingRect.Height);
// Select in the drawing surface
//IntPtr hOldFromBitmap = WindowsAPI.SelectObject(hDCFrom, bmFrom);
//IntPtr hOldToBitmap = WindowsAPI.SelectObject(hDCTo, bmTo);
// Draw in the memory device context
using (Graphics gHeaderDC = Graphics.FromHdc((To > From) ? hDCTo : hDCFrom))
{
DrawBandBitmap(hDCFrom, bands[From], From, drawingRect);
DrawBandBitmap(hDCTo, bands[To], To, drawingRect);
DrawHeader(gHeaderDC, To, new Rectangle(drawingRect.Left, drawingRect.Top,
drawingRect.Width, drawingRect.Top + BAND_HEADER_HEIGHT), Border3DStyle.RaisedInner);
Rectangle rectFrom = GetHeaderRect(From);
Rectangle rectTo = GetHeaderRect(To);
int headerHeight = rectFrom.Height;
// Do the animation with the bitmaps
if (To > From)
{
for (int y = rectTo.Top - headerHeight; y > rectFrom.Bottom; y -= headerHeight)
{
// Draw From bitmap
WindowsAPI.BitBlt(hDC, viewPortRect.Left, rectFrom.Bottom + 1,
viewPortRect.Width, y - rectFrom.Bottom - 1, hDCFrom, 0, 0, (int)PatBltTypes.SRCCOPY);
// Draw To Bitmap
WindowsAPI.BitBlt(hDC, viewPortRect.Left, y, viewPortRect.Width,
viewPortRect.Bottom - y + headerHeight, hDCTo, 0, 0, (int)PatBltTypes.SRCCOPY);
Thread.Sleep(animationSpeed);
}
}
else
{
Rectangle rcTo = new Rectangle(viewPortRect.Left,
viewPortRect.Bottom, viewPortRect.Width, viewPortRect.Bottom - headerHeight);
for (int y = rectFrom.Top + 1; y < rcTo.Top - headerHeight; y += headerHeight)
{
// Draw To Bitmap
WindowsAPI.BitBlt(hDC, viewPortRect.Left, rectFrom.Top, viewPortRect.Width,
y - rectFrom.Top - 1, hDCTo, 0, 0, (int)PatBltTypes.SRCCOPY);
// Draw From bitmap
WindowsAPI.BitBlt(hDC, viewPortRect.Left, y,
viewPortRect.Width, viewPortRect.Bottom - y, hDCFrom, 0, 0, (int)PatBltTypes.SRCCOPY);
Thread.Sleep(animationSpeed);
}
}
}
// Cleanup
WindowsAPI.ReleaseDC(Handle, hDC);
WindowsAPI.DeleteDC(hDCFrom);
WindowsAPI.DeleteDC(hDCTo);
WindowsAPI.SelectObject(hDCFrom, bmFrom);
WindowsAPI.SelectObject(hDCTo, bmTo);
WindowsAPI.DeleteObject(bmFrom);
WindowsAPI.DeleteObject(bmTo);
}