在寫一此協助說明類的文檔時,截取的圖片如果還有滑鼠的指標形狀,看起來就更直觀更友好一些。接下來就講一下如何在中包含滑鼠指標形狀。
添加結構CURSORINFO:
[StructLayout(LayoutKind.Sequential)] struct CURSORINFO { public int cbSize; public int flags; public IntPtr hCursor; public Point ptScreenPos; }
聲明API:
[DllImport("user32.dll")] static extern bool GetCursorInfo(out CURSORINFO pci);
定義枚舉值:
private const int CURSOR_SHOWING = 0x00000001;
添加方法:
/// <summary> /// 將滑鼠指標形狀繪製到螢幕上 /// </summary> /// <param name="g"></param> private void DrawCursorImageToScreenImage(ref Graphics g) { if (!this.IsCutCursor) { return; } CURSORINFO vCurosrInfo; vCurosrInfo.cbSize = Marshal.SizeOf(typeof(CURSORINFO)); GetCursorInfo(out vCurosrInfo); if ((vCurosrInfo.flags & CURSOR_SHOWING) != CURSOR_SHOWING) return; Cursor vCursor = new Cursor(vCurosrInfo.hCursor); Rectangle vRectangle = new Rectangle(new Point(vCurosrInfo.ptScreenPos.X - vCursor.HotSpot.X, vCurosrInfo.ptScreenPos.Y - vCursor.HotSpot.Y), vCursor.Size); vCursor.Draw(g, vRectangle); }
添加方法調用:
OK,再去看看吧!