自由改变鼠标的特效c#代码怎么写? 自由改变鼠标的特效c#代码怎么写?最好我可以加图片 想要什么样子就什么样子可以么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System.Runtime.InteropServices; using System.Reflection; C# winForm自定义鼠标样式方法一导入API[DllImport("user32.dll")] ublic static extern IntPtr LoadCursorFromFile(string fileName); [DllImport("user32.dll")] ublic static extern IntPtr SetCursor(IntPtr cursorHandle); [DllImport("user32.dll")] ublic static extern uint DestroyCursor(IntPtr cursorHandle); 接下来使用自己的鼠标样式 private void Form1_Load(object sender, EventArgs e) { Cursor myCursor = new Cursor(Cursor.Current.Handle); IntPtr colorCursorHandle = LoadCursorFromFile("my.cur");//图片格式可以为:PNG,ICO等 myCursor.GetType().InvokeMember("handle", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField, null, myCursor, new object[] { colorCursorHandle }); this.Cursor = myCursor; } C# winForm自定义鼠标样式方法之二现在介绍另一种不用API方式的,鼠标样式只需要一张背景透明的图片就行了,png或gif格式的写个方法 public void SetCursor(Bitmap cursor, Point hotPoint) { int hotX = hotPoint.X; int hotY = hotPoint.Y; Bitmap myNewCursor = new Bitmap(cursor.Width * 2 - hotX, cursor.Height * 2 - hotY); Graphics g = Graphics.FromImage(myNewCursor); g.Clear(Color.FromArgb(0, 0, 0, 0)); g.DrawImage(cursor, cursor.Width - hotX, cursor.Height - hotY, cursor.Width, cursor.Height); this.Cursor = new Cursor(myNewCursor.GetHicon()); g.Dispose(); myNewCursor.Dispose(); } 在你想要改变鼠标样式的事件里头使用这个方法就行了private void Form1_Load(object sender, EventArgs e) { Bitmap a=(Bitmap)Bitmap.FromFile("myCur.png"); SetCursor(a, new Point(0, 0)); } 200分,用DataSet实现内存数据库的设想,发帖探讨 Oracle NUMBER(10,2) 这种类型在C# 对应什么? 请教C#双击获取屏幕坐标 c#怎么控制系统声音 c# dataset 问题! 菜单和工具栏的颜色 关于图标修改 设置一个文件夹的透明度 DateTime 如何修改JpegBitmapEncoder对象大小 浅谈GUID会不会重复 求解一个三元一次方程的程序
using System.Reflection;
C# winForm自定义鼠标样式方法一
导入API
[DllImport("user32.dll")]
ublic static extern IntPtr LoadCursorFromFile(string fileName);
[DllImport("user32.dll")]
ublic static extern IntPtr SetCursor(IntPtr cursorHandle);
[DllImport("user32.dll")]
ublic static extern uint DestroyCursor(IntPtr cursorHandle);
接下来使用自己的鼠标样式
private void Form1_Load(object sender, EventArgs e)
{
Cursor myCursor = new Cursor(Cursor.Current.Handle);
IntPtr colorCursorHandle = LoadCursorFromFile("my.cur");//图片格式可以为:PNG,ICO等
myCursor.GetType().InvokeMember("handle", BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.SetField, null, myCursor,
new object[] { colorCursorHandle });
this.Cursor = myCursor;
}
C# winForm自定义鼠标样式方法之二
现在介绍另一种不用API方式的,鼠标样式只需要一张背景透明的图片就行了,png或gif格式的
写个方法
public void SetCursor(Bitmap cursor, Point hotPoint)
{
int hotX = hotPoint.X;
int hotY = hotPoint.Y;
Bitmap myNewCursor = new Bitmap(cursor.Width * 2 - hotX, cursor.Height * 2 - hotY);
Graphics g = Graphics.FromImage(myNewCursor);
g.Clear(Color.FromArgb(0, 0, 0, 0));
g.DrawImage(cursor, cursor.Width - hotX, cursor.Height - hotY, cursor.Width,
cursor.Height);
this.Cursor = new Cursor(myNewCursor.GetHicon());
g.Dispose();
myNewCursor.Dispose();
}
在你想要改变鼠标样式的事件里头使用这个方法就行了
private void Form1_Load(object sender, EventArgs e)
{
Bitmap a=(Bitmap)Bitmap.FromFile("myCur.png");
SetCursor(a, new Point(0, 0));
}