当前位置:首页 > 开发 > C# > 正文内容

C# 捕获鼠标

C#3年前 (2022-11-03)
方式一-API    
/// <summary>
/// 捕获鼠标
/// </summary>
/// <param name="hwnd"></param>
/// <returns></returns>
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetCapture(IntPtr hwnd);
/// <summary>
/// 释放鼠标
/// </summary>
/// <returns></returns>
[DllImport("user32.dll", SetLastError = true)]
public static extern bool ReleaseCapture()


方式二    
Control.Capture;


通过捕获鼠标改变指针    
Cursor cursor;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
    Bitmap bitmap = Properties.Resources._111;
    cursor = new Cursor(bitmap.GetHicon());
    pictureBox1.Cursor = cursor;
    SetCapture(pictureBox1.Handle);
    bitmap.Dispose();
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
    cursor.Dispose();
    ReleaseCapture();
    pictureBox1.Cursor = Cursors.Default;
}



转载请注明出处。

本文链接:http://www.pythonopen.com/?id=245

相关文章

C# 颜色算法

RGB转Dec    /// <summary>...

C# 请确保您的 Main 函数带有 STAThreadAttribute 标记。”

System.Threading.ThreadStateException:“在可以调用 OLE 之...

在 C# 中实现类似于 Windows 资源管理器的“名称”排序方式

要在 C# 中实现类似于 Windows 资源管理器的“名称”排序方式,你需要考虑以下几点:1. 不...

C# 可空参数

using System; using System.Runtime.Inte...

C# 跳出foreach循环

在 C# 中,如果你想在 foreach 循环内部提前跳出当前这一轮循环,继续执行下一轮循环,可以使...