如何在c#中检查鼠标是否移动,同时鼠标左键按下

时间:2022-11-05 13:49:25

I need to find a way to check if the mouse moves in c#, while the left button is down.

我需要找到一种方法来检查鼠标是否在c#中移动,而左键是否已关闭。

1 个解决方案

#1


22  

Here's an example (WPF):

这是一个例子(WPF):

public MainWindow()
{
    InitializeComponent();
    this.MouseMove += new MouseEventHandler(MainWindow_MouseMove);
}

void MainWindow_MouseMove(object sender, MouseEventArgs e)
{
    if (e.LeftButton == MouseButtonState.Pressed)
    {
        //do something
    }
}

#1


22  

Here's an example (WPF):

这是一个例子(WPF):

public MainWindow()
{
    InitializeComponent();
    this.MouseMove += new MouseEventHandler(MainWindow_MouseMove);
}

void MainWindow_MouseMove(object sender, MouseEventArgs e)
{
    if (e.LeftButton == MouseButtonState.Pressed)
    {
        //do something
    }
}