Home >Backend Development >C#.Net Tutorial >C# development example-customized screenshot tool (10) including the mouse pointer shape in the screenshot
When writing a help document, the intercepted pictureif there is a mouse pointer shape, it will look more intuitive and friendly. Next, let’s talk about how to include the mouse pointer shape in the screenshot.
[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, let’s take a screenshot again!
The above is the detailed content of C# development example-customized screenshot tool (10) including the mouse pointer shape in the screenshot. For more information, please follow other related articles on the PHP Chinese website!