【发布时间】: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
private void button_Click(object sender, MouseEventArgs e)
{
if (e.Button == MouseButton.Right)
{
}
}
代码在 WPF 中不起作用...我们将不胜感激。感谢离子推进。
【问题讨论】:
标签: c# wpf mouseevent right-click
在 WPF 中,您可以使用事件MouseDown 和MouseUp,它们提供MouseButtonEventArgs。 Click 事件仅针对鼠标主按钮引发(取决于系统设置)。
还有MouseLeftButtonDown/MouseLeftButtonUp和MouseRightButtonDown/MouseRightButtonUp事件。
【讨论】:
按钮单击事件只会由鼠标主按钮引发。然而,这些可以在系统设置中为右手/左手用户交换。
如果需要知道是左键还是右键,可以通过SystemParameters获取。
private void OnClick(object sender, RoutedEventArgs e)
{
if (SystemParameters.SwapButtons)
{
// It's the right button.
}
else
{
// It's the standard left button.
}
}
【讨论】:
您应该使用 mousedown 或 mouseup 事件而不是 click 事件,这样您就可以从 MouseEventArgs e 检测到,例如 if (e.Button == MouseButtons.Left)
【讨论】: