简体   繁体   English

查看是否在OnMouseMove事件中按住鼠标左键

[英]See if left mouse button is held down in the OnMouseMove event

如何检测控件的OnMouseMove事件中是否按下了鼠标左键?

Your eventhandler for the OnMouseMove event should recieve a MouseEventArgs that should tell you if the left button is pressed 你的OnMouseMove事件的事件处理程序应该收到一个MouseEventArgs ,它应该告诉你是否按下了左键

private void mouseMoveEventHandler(object sender, MouseEventArgs e)
{
   if(e.Button == MouseButtons.Left)
   {
     //do left stuff
   }
   else 
   {
     // do other stuff
   }
}

Simply have a boolean set to true when the left mouse button is held and set it to false when its released. 按住鼠标左键时,只需将布尔值设置为true,并在释放时将其设置为false。

If you check the condition of the bool when you fire the OnMouseMove event then you will be able to find out if its held down or not. 如果你在开启OnMouseMove事件时检查bool的状态,那么你将能够找出它是否被按下。

Psuedo code: Psuedo代码:

private bool isDown;

MouseDown()
{
   isDown = true;
}

MouseUp()
{
   isDown = false;
}
OnMouseMove()
{
   if(isDown)
   {
       //Do something...
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM