当前位置:首页 > 开发 > 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# 可空参数

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

C# 缩减代码量的一些方式

static void Main() { Thread thre...

C# BackgroundWorker

1.概述BackgroundWorker是一个在 WinForms 应用程序中用于简化在后台线程执行...

C# [OnPaint]和[OnPaintBackground]的区别

OnPaint和OnPaintBackground的主要功能区别OnPaint:OnPaint方法主...

C# Browsable(bool)

在编程中(比如常见的 C# 语言在开发 Windows Forms 等应用程序时),Browsabl...

C# OnMeasureItem

1. **整体功能概述**   - `OnMeasureItem` 是一个在Wi...