当前位置:首页 > 开发 > 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://pythonopen.com/?id=245

相关文章

C# protected

官方:只有在通过派生类类型发生访问时,基类的受保护成员在派生类中才是可访问的。 简单理解:...

C# 正则表达式

命名空间    using System.Text.Regu...

C# MDI例子

父窗口属性IsMdiContainer设置为Trueprivate void b...

C# Byte[]转为Bitmap

在 C# 中,可以使用System.Drawing命名空间下的相关类将byte[]类型的数据转换为B...

C# Byte[]转为Image

以下是在 C# 中将byte[](字节数组,通常表示图像的二进制数据)转换为Image类型的常见方法...

C# MemoryStream转为Image

        //...