我试着像我在一些例子中发现的那样做:
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':委托的无效参数构造函数;委托目标需要是指向成员的指针函数
桥是非托管类。我这样声明TimerID
gcroot<System::Windows::Forms::Timer ^> TimerID;
我在这里做错了什么?如何正确添加Tick事件
您没有发布足够的代码来诊断错误。这个编译:
public ref class Bridge : public System::Windows::Forms::Form
{
Timer^ TimerID;
public:
Bridge(void) {
InitializeComponent();
TimerID = gcnew System::Windows::Forms::Timer();
TimerID->Tick += gcnew System::EventHandler(this, &Bridge::timer1_Tick);
}
private:
void Bridge::timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
}
void InitializeComponent(void) {
// etc...
}
};