捕获标签上同时的右键和左键单击事件触发器
我正在圣诞节假期期间编写一个简单的扫雷游戏,并添加了一个功能,您可以在一个数字上单击两个鼠标按钮,然后在安全的情况下,它会显示该数字周围的隐藏框。即数字是 1 并且您标记了 1 个地雷,因此它会发现 1 旁边的所有其他框。快速旁注:我喜欢扫雷是一个标签。
我在标签上有一个鼠标单击事件,但 System.Windows.Forms.MouseButtons
没有“左右按钮一起”选项。那么,我该怎么做呢?
private void label1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left &&
e.Button == System.Windows.Forms.MouseButtons.Right)
{
MessageBox.Show("doesn't work");
}
}
I'm writing a simple minesweeper game over my Christmas break and I'm adding in the feature where you click with both mouse buttons on a number and it unveils the hidden boxes around it when it's safe to do so. ie the number is a 1 and you've flagged 1 mine, so it uncovers all other boxes next to the 1. Quick side note: I love that minesweeper is a tag.
I have a mouse click event on the label, but there is no "Both right and left buttons together" option for System.Windows.Forms.MouseButtons
. So, how do I do this?
private void label1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left &&
e.Button == System.Windows.Forms.MouseButtons.Right)
{
MessageBox.Show("doesn't work");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能这样做——要么是左,要么是右,要么是无,而不是两者。
但是,您可以模拟它。
您可以保存单击的按钮以及当前时间,
然后,在下次单击时,如果按下的按钮与第一次单击不同,
假设时间差 <10 毫秒,则将其计为单击了两个按钮
You can't do that - it's either Left or Right or None, not BOTH.
BUT, you can simulate it.
you can save which button was clicked, along with the current time,
then, on the next click, if the pressed button is DIFFERENT than the first click,
and the time difference is, lets say, <10ms, then count it as BOTH buttons clicked