C#鼠标指针首先要从获取鼠标句柄开始,另外会制定例如悬停、点击等等不同手势的设定,以及不同样式的设定。
系统设置了C#鼠标指针的样式 可以通过下面的方法设置程序的鼠标指针样式。
- view plaincopy to clipboardprint?
- [DllImport("user32.dll", EntryPoint = "SetCursor")]
- public static extern IntPtr SetCursor(IntPtr hCursor);
- ///
- /// 获取鼠标句柄
- ///
- /// IntPtr.Zero
- /// 样式
- ///
- [DllImport("User32.dll", CharSet = CharSet.Auto)]
- public static extern IntPtr LoadCursor(IntPtr hInstance, CursorType cursor);
- public enum CursorType : uint
- {
- IDC_ARROW = 32512U,
- IDC_IBEAM = 32513U,
- IDC_WAIT = 32514U,
- IDC_CROSS = 32515U,
- IDC_UPARROW = 32516U,
- IDC_SIZE = 32640U,
- IDC_ICON = 32641U,
- IDC_SIZENWSE = 32642U,
- IDC_SIZENESW = 32643U,
- IDC_SIZEWE = 32644U,
- IDC_SIZENS = 32645U,
- IDC_SIZEALL = 32646U,
- IDC_NO = 32648U,
- IDC_HAND = 32649U,
- IDC_APPSTARTING = 32650U,
- IDC_HELP = 32651U
- }
- private void Form1_MouseMove(object sender, MouseEventArgs e)
- {
- IntPtr _HandCursorIntPrt = LoadCursor(IntPtr.Zero, CursorType.IDC_HAND);
- SetCursor(_HandCursorIntPrt);
- }
获取系统的C#鼠标指针相关代码解析就介绍到这里。
【编辑推荐】