Visual c++检测右键单击按钮
Visual C++ Detect a Right Click on a Button
我有一个程序,我想在一个按钮上右键单击做一个完全不同的代码量。我让代码在示例中显示一个消息框,但最终它将只是每个方法调用。我会告诉你我需要它的背景。关于如何检测右键的任何和所有帮助都会有所帮助。下面是我的代码片段:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ buttonName = safe_cast<Button^>(sender)->Name;
safe_cast<Button^>(sender)->Enabled = false;
if(/*Insert Code Here To Detect a right click*/)
MessageBox::Show("Right Click");
else
MessageBox::Show("Left Click");
MessageBox::Show(buttonName);
}
};
你可以使用MouseDown事件并检查它是否正确
void button1_MouseDown( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e )
{
// Update the mouse path with the mouse information
Point mouseDownLocation = Point(e->X,e->Y);
String^ eventString = nullptr;
switch ( e->Button )
{
case ::MouseButtons::Left:
eventString = "L";
break;
case ::MouseButtons::Right:
eventString = "R";
break;
case ::MouseButtons::Middle:
eventString = "M";
break;
case ::MouseButtons::XButton1:
eventString = "X1";
break;
case ::MouseButtons::XButton2:
eventString = "X2";
break;
case ::MouseButtons::None:
default:
break;
}
//Process Here...
}
相关文章:
- ImGui 在单击按钮后冻结
- 如何在单击按钮FLTK的确切时刻获得小部件的值
- 如何使linedit准备好在单击按钮时键入
- 如何通过单击按钮在QTextEdit中显示文本?
- 通过单击按钮更改标签 GTK C.
- Qt在单击按钮时调用Child-Window
- 如何使 UI 对象仅在单击按钮后显示在对话框中
- Qt C++单击按钮的事件
- 如何使用C++禁用窗口上的右键单击按钮
- 事件仅在单击按钮时检查
- 右键单击按钮GTKMM-3.0的信号
- 如何通过单击按钮在窗口上生成对象
- 单击按钮后,如何在QT中更改窗口中的信息
- 单击按钮时控制qt中的循环
- 尝试在单击按钮时捕获编辑框中的文本,然后显示到另一个编辑框
- 单击按钮时,全局变量包含垃圾
- 单击按钮后对QML矩形的颜色设置动画
- 正在检测何时单击按钮?[C++,WinAPI]
- 单击按钮时显示另一个 UI 文件
- 如果我单击按钮,则在 MFC 中调用函数