我正在尝试将事件绑定到menuitem。它汇编。但是,当单击“关于”菜单项时,没有任何反应。请帮忙!
ref class MenuEventListener
{
public:
MenuEventListener (System::Windows::Forms::Form ^form)
{
this->form = form;
this->form->Click += gcnew EventHandler (this, &MenuEventListener::AboutClick);
}
private:
System::Windows::Forms::Form^ form;
void AboutClick (Object^ sender, System::EventArgs^ args)
{
System::String ^text = gcnew System::String ("This is an about message");
System::String ^cap = gcnew System::String("About");
System::Windows::Forms::MessageBox::Show (
(IWin32Window^) Control::FromHandle (form->Handle),
text, cap,
System::Windows::Forms::MessageBoxButtons::OK,
System::Windows::Forms::MessageBoxIcon::Question);
}
};
// Called in the form constructor
menuEventListener = gcnew MenuEventListener (this);
哦,如果有人可以解释事件处理程序的概念,具体来说,实际上如何使用“类事件”及其与事件引发函数的关系,例如OnClick。我得到它,但几乎没有。这样的人希望有人解释他们是否善意。
编辑: 以下是about菜单的上下文
TextEditorMenu::TextEditorMenu ()
{
// Create components
menu = gcnew System::Windows::Forms::MainMenu ();
fileMenuItem = gcnew System::Windows::Forms::MenuItem ();
helpMenuItem = gcnew System::Windows::Forms::MenuItem ();
newMenuItem = gcnew System::Windows::Forms::MenuItem ();
openMenuItem = gcnew System::Windows::Forms::MenuItem ();
saveMenuItem = gcnew System::Windows::Forms::MenuItem ();
saveAsMenuItem = gcnew System::Windows::Forms::MenuItem ();
aboutMenuItem = gcnew System::Windows::Forms::MenuItem ();
// Intizlize components
fileMenuItem->Text = "File";
helpMenuItem->Text = "Help";
aboutMenuItem->Text = "About";
newMenuItem->Text = "New File";
openMenuItem->Text = "Open File";
saveMenuItem->Text = "Save";
saveAsMenuItem->Text = "Save As";