如何C#自定义鼠标图片
privatevoidpanel1_MouseMove(objectsender,MouseEventArgse){this.panel1.Cursor=newCurso...
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
this.panel1.Cursor = new Cursor("chuizi1.ico");
}
private void pictureBox02_MouseUp(object sender, MouseEventArgs e)
{
this.panel1.Cursor = new Cursor("chuizi1.ico");
}
代码报错 显示图片已损坏 展开
{
this.panel1.Cursor = new Cursor("chuizi1.ico");
}
private void pictureBox02_MouseUp(object sender, MouseEventArgs e)
{
this.panel1.Cursor = new Cursor("chuizi1.ico");
}
代码报错 显示图片已损坏 展开
4个回答
展开全部
hi,项目中也用到了这个,你可以尝试这个方式读取:
internal class BitmapCursor : SafeHandle {
public override bool IsInvalid
{
get
{
return handle == (IntPtr)(-1);
}
}
public static Cursor CreateBmpCursor(Bitmap cursorBitmap)
{
var c = new BitmapCursor(cursorBitmap);
return CursorInteropHelper.Create(c); }
protected BitmapCursor(Bitmap cursorBitmap)
: base((IntPtr)(-1), true)
{
handle = cursorBitmap.GetHicon();
}
protected override bool ReleaseHandle()
{
bool result = DestroyIcon(handle);
handle = (IntPtr)(-1);
return result; }
[DllImport("user32.dll")] public static extern bool DestroyIcon(IntPtr hIcon);
public static Cursor CreateCrossCursor()
{
const int w = 25;
const int h = 25;
var bmp = new Bitmap(w, h);
string imgPath = ""; // Your Absolute ImagePath
if (HelperMethods.DevelopMode())
{
System.Windows.Forms.MessageBox.Show(imgPath);
}
if (System.IO.File.Exists(imgPath))
{
bmp = new Bitmap(imgPath);
}
else
{
//系统图标
Graphics g = Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.Default;
g.InterpolationMode = InterpolationMode.High;
var pen = new Pen(Brushes.Black, 2);
g.DrawLine(pen, new Point(12, 0), new Point(12, 8)); // vertical line
g.DrawLine(pen, new Point(12, 17), new Point(12, 25)); // vertical line
g.DrawLine(pen, new Point(0, 12), new Point(8, 12)); // horizontal line
g.DrawLine(pen, new Point(16, 12), new Point(24, 12)); // horizontal line
g.DrawLine(pen, new Point(12, 12), new Point(12, 13)); // Middle dot
g.Flush();
g.Dispose();
pen.Dispose();
}
var c = CreateBmpCursor(bmp);
bmp.Dispose();
return c;
}
}
internal class BitmapCursor : SafeHandle {
public override bool IsInvalid
{
get
{
return handle == (IntPtr)(-1);
}
}
public static Cursor CreateBmpCursor(Bitmap cursorBitmap)
{
var c = new BitmapCursor(cursorBitmap);
return CursorInteropHelper.Create(c); }
protected BitmapCursor(Bitmap cursorBitmap)
: base((IntPtr)(-1), true)
{
handle = cursorBitmap.GetHicon();
}
protected override bool ReleaseHandle()
{
bool result = DestroyIcon(handle);
handle = (IntPtr)(-1);
return result; }
[DllImport("user32.dll")] public static extern bool DestroyIcon(IntPtr hIcon);
public static Cursor CreateCrossCursor()
{
const int w = 25;
const int h = 25;
var bmp = new Bitmap(w, h);
string imgPath = ""; // Your Absolute ImagePath
if (HelperMethods.DevelopMode())
{
System.Windows.Forms.MessageBox.Show(imgPath);
}
if (System.IO.File.Exists(imgPath))
{
bmp = new Bitmap(imgPath);
}
else
{
//系统图标
Graphics g = Graphics.FromImage(bmp);
g.SmoothingMode = SmoothingMode.Default;
g.InterpolationMode = InterpolationMode.High;
var pen = new Pen(Brushes.Black, 2);
g.DrawLine(pen, new Point(12, 0), new Point(12, 8)); // vertical line
g.DrawLine(pen, new Point(12, 17), new Point(12, 25)); // vertical line
g.DrawLine(pen, new Point(0, 12), new Point(8, 12)); // horizontal line
g.DrawLine(pen, new Point(16, 12), new Point(24, 12)); // horizontal line
g.DrawLine(pen, new Point(12, 12), new Point(12, 13)); // Middle dot
g.Flush();
g.Dispose();
pen.Dispose();
}
var c = CreateBmpCursor(bmp);
bmp.Dispose();
return c;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
-“控制面板”---“鼠标”---在“鼠标属性”里找到“指针”---“自定义”里点一下你要改的鼠标样子---在点“浏览”找到电脑已经有的跟换鼠标的图片---按“确定”就完成了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你图片地址呢?
追问
图片在 bin 的 begu里
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询