在写一此帮助说明类的文档时,截取的图片如果还有鼠标的指针形状,看起来就更直观更友好一些。接下来就讲一下如何在截图中包含鼠标指针形状。
[StructLayout(LayoutKind.Sequential)] struct CURSORINFO { public int cbSize; public int flags; public IntPtr hCursor; public Point ptScreenPos; }
[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,再去截图看看吧!
以上是C#开发实例-订制屏幕截图工具(十)在截图中包含鼠标指针形状的详细内容。更多信息请关注PHP中文网其他相关文章!