/// <summary> /// Begin using off-screen buffer and cache drawing which will be done after. /// </summary> /// <param name="paintRect">painting area (used for creating off-screen buffer).</param> public void BeginPaint(Rectangle paintRect) { Debug.Assert(_MemDC == IntPtr.Zero, "invalid state; _MemDC must be IntPtr.Zero."); Debug.Assert(_MemBmp == IntPtr.Zero, "invalid state; _MemBmp must be IntPtr.Zero."); // create offscreen from the window DC _MemDC = WinApi.CreateCompatibleDC(_DC); _MemBmp = WinApi.CreateCompatibleBitmap(_DC, paintRect.Width, paintRect.Height); _Offset = paintRect.Location; _MemDcSize = paintRect.Size; _OrgMemBmp = WinApi.SelectObject(_MemDC, _MemBmp); }
/// <summary> /// End using off-screen buffer and flush all drawing results. /// </summary> public void EndPaint() { Debug.Assert(_MemDC != IntPtr.Zero, "invalid state; EndPaint was called before" + " BeginPaint."); const uint SRCCOPY = 0x00CC0020; // flush cached graphic update WinApi.BitBlt(_DC, _Offset.X, _Offset.Y, _MemDcSize.Width, _MemDcSize.Height, _MemDC, 0, 0, SRCCOPY); RemoveClipRect(); // dispose resources used in off-screen rendering WinApi.SelectObject(_MemDC, _OrgMemBmp); WinApi.DeleteDC(_MemDC); _MemDC = IntPtr.Zero; SafeDeleteObject(_MemBmp); _MemBmp = IntPtr.Zero; // reset graphic coordinate offset _Offset.X = _Offset.Y = 0; }