在Visual Studio(VS)里面的窗体怎么设置鼠标的光标?
Cursor属性里面的都是常用的,我想要自定义光标图像,现在我已经有了一个"鼠标.cur"文件了,接下来应该怎么做?求高人解答...
Cursor属性里面的都是常用的,我想要自定义光标图像,现在我已经有了一个"鼠标.cur"文件了,接下来应该怎么做?求高人解答
展开
2个回答
展开全部
//1、加载cur光标文件
Cursor = new Cursor(@"E:\Projects\Test01\Test01\myCursor.cur");
//****System .Drawing.Icon f =new Icon (,)
//***f.Handle () 和加载图片类似
//2、加载图片设置为光标
Bitmap bm = (Bitmap)Image.FromFile(@"E:\Projects\Test01\Test01\myPicture.jpg");
Cursor = new Cursor(bm.GetHicon());
//3、加载ani光标文件(另,也可以加载格式为cur和ico的光标文件)
//需要添加一下两个引用:
//using System.Runtime.InteropServices;
//using System.Reflection;
//另:
//[DllImport("user32.dll")]
//public static extern IntPtr LoadCursorFromFile(string fileName);
//[DllImport("user32.dll")]
//public static extern IntPtr SetCursor(IntPtr cursorHandle);
//[DllImport("user32.dll")]
//public static extern uint DestroyCursor(IntPtr cursorHandle);
Cursor myCursor = new Cursor(Cursor.Current.Handle);
IntPtr colorCursorHandle = LoadCursorFromFile(@"E:\Projects\Test01\Test01\myAni.ani");
myCursor.GetType().InvokeMember("handle", BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.SetField, null, myCursor,
new object[] { colorCursorHandle });
Cursor = myCursor
Cursor = new Cursor(@"E:\Projects\Test01\Test01\myCursor.cur");
//****System .Drawing.Icon f =new Icon (,)
//***f.Handle () 和加载图片类似
//2、加载图片设置为光标
Bitmap bm = (Bitmap)Image.FromFile(@"E:\Projects\Test01\Test01\myPicture.jpg");
Cursor = new Cursor(bm.GetHicon());
//3、加载ani光标文件(另,也可以加载格式为cur和ico的光标文件)
//需要添加一下两个引用:
//using System.Runtime.InteropServices;
//using System.Reflection;
//另:
//[DllImport("user32.dll")]
//public static extern IntPtr LoadCursorFromFile(string fileName);
//[DllImport("user32.dll")]
//public static extern IntPtr SetCursor(IntPtr cursorHandle);
//[DllImport("user32.dll")]
//public static extern uint DestroyCursor(IntPtr cursorHandle);
Cursor myCursor = new Cursor(Cursor.Current.Handle);
IntPtr colorCursorHandle = LoadCursorFromFile(@"E:\Projects\Test01\Test01\myAni.ani");
myCursor.GetType().InvokeMember("handle", BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.SetField, null, myCursor,
new object[] { colorCursorHandle });
Cursor = myCursor
更多追问追答
追问
哥们,你复制的东西我看不懂啊,能具体说说吗?
追答
在Load事件里面把这段代码加进去就行了
来个简单的:
Cursor mycur = new Cursor(this.GetType(), "鼠标.cur");
this.Cursor = mycur;
这是我以前弄过的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询