脚本宝典收集整理的这篇文章主要介绍了C# 自定义鼠标样式 1,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
接上一篇,不调用 API 的方式。
using System;
using System.Collections.Generic;
using System.componentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MouseSt
{
using System.Runtime.InteropServices;
using System.Reflection;
public partial class Form1 : Form
{
public Form1()
{
InITializeComponent();
}
PRivate void Form1_Load(object sender, Eventargs e)
{
Bitmap a = (Bitmap)Bitmap.FromFile("1.gif");
SetCursor(a, new Point(0, 0));
}
public void SetCursor(Bitmap cursor, Point hotPoint)
{
int hotX = hotPoint.X;
int hotY = hotPoint.Y;
// 这里为什么要 * 2
Bitmap myNewCursor = new Bitmap(cursor.Width * 2 - hotX, cursor.Height * 2 - hotY);
Graphics graphics = Graphics.FromImage(myNewCursor);
graphics.Clear(Color.FromArgb(0, 0, 0, 0));
graphics.DrawImage(cursor, cursor.Width - hotX, cursor.Height - hotY, cursor.Width, cursor.Height);
this.Cursor = new Cursor(myNewCursor.GetHicon());
graphics.Dispose();
myNewCursor.Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("被点击!");
}
}
}
Bitmap myNewCursor
为什么要 *2
? 没看明白。 因为 Cursor 属性计算定位的是样式图片的中心点位置?
以上是脚本宝典为你收集整理的C# 自定义鼠标样式 1全部内容,希望文章能够帮你解决C# 自定义鼠标样式 1所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。