按下并释放按钮

时间:2015-10-08 11:58:55

标签: c# button

我希望按钮的功能如下:

if button is down(mouse button is hold down)
{
   bool trySmthing = true;
}

if button is up
{
   bool trySmthing = false;
}

我尝试了KeyUpKeyDown个事件,但他们没有给出正确的结果。

2 个答案:

答案 0 :(得分:3)

显然,重点必须放在你的申请中;可以找到一个关于通过C#中的.NET框架处理鼠标事件的教程here。记录为hereMouseDown事件和记录为hereMouseUp事件特别令人感兴趣。

答案 1 :(得分:0)

这应该有所帮助:Micosoft Library for C# Mouse-events

void MouseUpHandler(Object sender, RoutedEventArgs args)
{
// This method is called whenever the PreviewMouseUp event fires.
}

void MouseDownHandler(Object sender, RoutedEventArgs args)
{
// This method is called whenever the PreviewMouseDown event fires.
}