获取鼠标状态而无法访问MouseEventArgs? [英] Get Mouse State without access to MouseEventArgs?
本文介绍了获取鼠标状态而无法访问MouseEventArgs?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含许多控件的表单.我需要检测鼠标是否向下或向上.大多数时候,我没有 MouseEventArgs .
I have a form with many, many controls. I need to detect if the mouse is down or if it's up. Most of the time, I don't have MouseEventArgs.
有没有一种快速简便的方法来判断没有mouseEventArgs的情况下鼠标是否按下?
Is there a quick and easy way to tell if the mouse is down without mouseEventArgs?
是否有替代方法,或者只有这样的方法?:
Is there an alternative, or is something like this the only way?:
foreach (Control c in this.Controls)
{
c.MouseUp += new MouseEventHandler(globalMouseUp);
c.MouseDown += new MouseEventHandler(globalMouseDown);
}
bool isMouseUp = true;
private void globalMouseDown(object sender, MouseEventArgs e)
{
isMouseUp = false;
}
private void globalMouseUp(object sender, MouseEventArgs e)
{
isMouseUp = true;
}
推荐答案
您可以尝试使用计时器进行检查:
You can try checking with a timer:
private void timer1_Tick(object sender, EventArgs e) {
this.Text = "Mouse Is " + (Control.MouseButtons == MouseButtons.Left);
}
这篇关于获取鼠标状态而无法访问MouseEventArgs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文