如何将 Tick 事件添加到非托管类中的 System::windows::Forms::Timer
我正在尝试像在某些示例中找到的那样执行此操作:
TimerID = gcnew System::Windows::Forms::Timer();
TimerID->Tick += gcnew System::EventHandler(this, &Bridge::timer1_Tick);
但是
System::Void Bridge::timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
Bridge::DoUpdate();
}
由于错误而无法创建事件处理程序:
错误 C3364:“System::EventHandler”:委托参数无效 构造函数;委托目标需要是指向成员的指针 功能
Bridge 是非托管类。 所以我这样声明 TimerID:
gcroot<System::Windows::Forms::Timer ^> TimerID;
我在这里做错了什么?如何正确添加Tick事件?
I'm trying to do it like I found in some example :
TimerID = gcnew System::Windows::Forms::Timer();
TimerID->Tick += gcnew System::EventHandler(this, &Bridge::timer1_Tick);
and
System::Void Bridge::timer1_Tick(System::Object^ sender, System::EventArgs^ e)
{
Bridge::DoUpdate();
}
But can't create event handler because of error :
error C3364: 'System::EventHandler' : invalid argument for delegate
constructor; delegate target needs to be a pointer to a member
function
Bridge is unmanaged class.
So I'm declaring TimerID this way :
gcroot<System::Windows::Forms::Timer ^> TimerID;
What am I doing wrong here ? How to add Tick event proper ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有发布足够的代码来诊断错误。这编译:
You didn't post enough code to diagnose the error. This compiles: