How do I detect if the left mouse button is being held down in the OnMouseMove
event for a control?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Your eventhandler for the OnMouseMove event should recieve a MouseEventArgs
that should tell you if the left button is pressed
private void mouseMoveEventHandler(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
//do left stuff
}
else
{
// do other stuff
}
}
回答2:
Simply have a boolean set to true when the left mouse button is held and set it to false when its released.
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.
Psuedo code:
private bool isDown;
MouseDown()
{
isDown = true;
}
MouseUp()
{
isDown = false;
}
OnMouseMove()
{
if(isDown)
{
//Do something...
}
}