private void button_Click(object sender, MouseEventArgs e)
{
if (e.Button == MouseButton.Right)
{
}
}
The Code is not working in WPF ... Help will be appreciated. Thanx ion advance.
In WPF you can use the events MouseDown
and MouseUp
, which provide MouseButtonEventArgs
. Click
events are only raised for the main mouse button (depending on the system settings).
There are also the events MouseLeftButtonDown
/ MouseLeftButtonUp
and MouseRightButtonDown
/ MouseRightButtonUp
.
The button click event will only be raised by the primary mouse button. However these can be swapped in system settings for right/left handed users.
If need to know whether it was the left or right button, then you can use the SystemParameters to obtain it.
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
检测到MouseEventArgs e
, if (e.Button == MouseButtons.Left)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.