C#窗体右键单击按钮

C#窗体右键单击按钮

本文介绍了的Visual C#窗体右键单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Visual C#中扫雷艇类型的游戏,我想有不同的事情发生时,我点击右键,左键点击一个按钮,我该怎么做呢?



我曾尝试这个代码,但只注册左边点击:

 私人无效button1_MouseClick(对象发件人,MouseEventArgs E) 
{
如果(e.Button == System.Windows.Forms.MouseButtons.Left)
{
MessageBox.Show(左);
}
如果(e.Button == System.Windows.Forms.MouseButtons.Right)
{
MessageBox.Show(右);
}

}


解决方案

您必须使用的MouseUp 的MouseDown 事件而不是点击事件捕捉右键。


I am trying to make a minesweeper type game in visual c# and I want to have different things happen when I right click and left click a button, how do I do this?

I have tried this code but it only registers left clicks:

    private void button1_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Left)
        {
            MessageBox.Show("Left");
        }
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
        {
            MessageBox.Show("Right");
        }

    }
解决方案

You will have to use the MouseUp or MouseDown event instead of the Click event to capture right click.

这篇关于的Visual C#窗体右键单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:50