【问题标题】:How i can Check button click is right or left in c#我如何在c#中检查按钮单击是向右还是向左
【发布时间】:2017-01-17 11:42:44
【问题描述】:
private void button_Click(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButton.Right)
    {
    }
} 

代码在 WPF 中不起作用...我们将不胜感激。感谢离子推进。

【问题讨论】:

    标签: c# wpf mouseevent right-click


    【解决方案1】:

    在 WPF 中,您可以使用事件MouseDownMouseUp,它们提供MouseButtonEventArgsClick 事件仅针对鼠标主按钮引发(取决于系统设置)。

    还有MouseLeftButtonDown/MouseLeftButtonUpMouseRightButtonDown/MouseRightButtonUp事件。

    【讨论】:

      【解决方案2】:

      按钮单击事件只会由鼠标主按钮引发。然而,这些可以在系统设置中为右手/左手用户交换。

      如果需要知道是左键还是右键,可以通过SystemParameters获取。

      private void OnClick(object sender, RoutedEventArgs e)
          {
              if (SystemParameters.SwapButtons) 
              {
                  // It's the right button.
              }
              else
              {
                  // It's the standard left button.
              }
          }
      

      【讨论】:

        【解决方案3】:

        您应该使用 mousedown 或 mouseup 事件而不是 click 事件,这样您就可以从 MouseEventArgs e 检测到,例如 if (e.Button == MouseButtons.Left)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-11-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多