鼠标自定义样式,在网上查了查,现在把找到的觉得不错的方法展示如下:
(1)
Bitmap cursor = (Bitmap)Bitmap.FromFile("20050129171521936.gif");//括号内填写本地图片路径
Bitmap myNewCursor = new Bitmap(cursor.Width * 2, cursor.Height * 2);
Graphics g = Graphics.FromImage(myNewCursor);
g.Clear(Color.FromArgb(0, 0, 0, 0));
g.DrawImage(cursor, cursor.Width, cursor.Height, cursor.Width,
cursor.Height);
Cursor.Current = new Cursor(myNewCursor.GetHicon());
g.Dispose();
myNewCursor.Dispose();
这种方法可以把png,gif等常用图标格式做成鼠标样式展现
(2)
Cursor myCursor = new Cursor(Cursor.Current.Handle);
string path= Path.GetDirectoryName(Path.GetDirectoryName( Application.StartupPath));
IntPtr colorCursorHandle = LoadCursorFromFile(path + @"\images\lgam376.cur");//鼠标图标路径
myCursor.GetType().InvokeMember("handle", BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance |
BindingFlags.SetField, null, myCursor,
new object[] { colorCursorHandle });
this.Cursor = myCursor;
这种方法是把已有的cur格式图片展现,可以把png,gif等常用图标格式做成鼠标样式展现