Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个代码:
System::Windows::Forms::MenuItem^ item = gcnew System::Windows::Forms::MenuItem("text"); item->Click += ...
如何将鼠标事件处理程序添加到项目?
首先,您需要定义一个具有预期签名的事件处理程序方法:
void ItemClicked(Object^ sender, EventArgs^ e) { // your code }
然后使用+=运算符注册它:
+=
item->Click += gcnew EventHandler(&ItemClicked); // if ItemClicked is static item->Click += gcnew EventHandler(this, &ItemClicked); // if instance