发布时间:2020-02-27编辑:佚名阅读(1668)
添加结构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) { 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); }
添加方法调用:
上一篇:C#窗体保持在最前
下一篇:C#实现远程控制的关键技术
0人
0人
1人
0人