本网站(662p.com)打包出售,且带程序代码数据,662p.com域名,程序内核采用TP框架开发,需要联系扣扣:2360248666 /wx:lianweikj
精品域名一口价出售:1y1m.com(350元) ,6b7b.com(400元) , 5k5j.com(380元) , yayj.com(1800元), jiongzhun.com(1000元) , niuzen.com(2800元) , zennei.com(5000元)
需要联系扣扣:2360248666 /wx:lianweikj
C#实现绘制鼠标的示例代码
mylove136 · 102浏览 · 发布于2022-12-23 +关注

这篇文章主要为大家详细介绍了如何利用C#实现绘制鼠标的效果,文中的示例代码讲解详细,对我们学习C#有一定的帮助,感兴趣的小伙伴可以跟随小编一起了解一下


实践过程

效果

代码

public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }
 
       private int _X, _Y;
 
       [StructLayout(LayoutKind.Sequential)]
       private struct ICONINFO
       {
           public bool fIcon;
           public Int32 xHotspot;
           public Int32 yHotspot;
           public IntPtr hbmMask;
           public IntPtr hbmColor;
       }
 
       [StructLayout(LayoutKind.Sequential)]
       private struct CURSORINFO
       {
           public Int32 cbSize;
           public Int32 flags;
           public IntPtr hCursor;
           public Point ptScreenPos;
       }
 
       [DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
       private static extern int GetSystemMetrics(int mVal);
 
       [DllImport("user32.dll", EntryPoint = "GetCursorInfo")]
       private static extern bool GetCursorInfo(ref CURSORINFO cInfo);
 
       [DllImport("user32.dll", EntryPoint = "CopyIcon")]
       private static extern IntPtr CopyIcon(IntPtr hIcon);
 
       [DllImport("user32.dll", EntryPoint = "GetIconInfo")]
       private static extern bool GetIconInfo(IntPtr hIcon, out ICONINFO iInfo);
 
       private void Form1_Load(object sender, EventArgs e)
       {
       }
 
       private Bitmap CaptureCursor(ref int _CX, ref int _CY)
       {
           IntPtr _Icon;
           CURSORINFO _CursorInfo = new CURSORINFO();
           ICONINFO _IconInfo;
           _CursorInfo.cbSize = Marshal.SizeOf(_CursorInfo);
           if (GetCursorInfo(ref _CursorInfo))
           {
               if (_CursorInfo.flags == 0x00000001)
               {
                   _Icon = CopyIcon(_CursorInfo.hCursor);
 
                   if (GetIconInfo(_Icon, out _IconInfo))
                   {
                       _CX = _CursorInfo.ptScreenPos.X - _IconInfo.xHotspot;
                       _CY = _CursorInfo.ptScreenPos.Y - _IconInfo.yHotspot;
                       return Icon.FromHandle(_Icon).ToBitmap();
                   }
               }
           }
 
           return null;
       }
 
       private void button1_Click(object sender, EventArgs e)
       {
           int x = Control.MousePosition.X;
           int y = Control.MousePosition.Y;
           pictureBox1.Image = CaptureCursor(ref x, ref y);
       }
   }


c#

相关推荐

PHP实现部分字符隐藏

沙雕mars · 1327浏览 · 2019-04-28 09:47:56
Java中ArrayList和LinkedList区别

kenrry1992 · 910浏览 · 2019-05-08 21:14:54
Tomcat 下载及安装配置

manongba · 975浏览 · 2019-05-13 21:03:56
JAVA变量介绍

manongba · 964浏览 · 2019-05-13 21:05:52
什么是SpringBoot

iamitnan · 1090浏览 · 2019-05-14 22:20:36
加载中

0评论

评论
分类专栏
小鸟云服务器
扫码进入手机网页