2012-06-18 38 views
0
  myWebClient->DownloadProgressChanged += gcnew DownloadProgressChangedEventHandler(&Form1::DownloadProgressCallback); 

给出了错误:如何让事件处理程序访问成员数据?

1>.\Form1.cpp(26) : error C3352: 'void Form1::DownloadProgressCallback(System::Object ^,System::Net::DownloadProgressChangedEventArgs ^)' : the specified function does not match the delegate type 'void (System::Object ^,System::Net::DownloadProgressChangedEventArgs ^)'

文档使用静态非成员函数,因为这代表参数,但我想更新Form1类的进度条成员。我在这里做错了什么?

我使用的是.NET 2.0,所以请尽可能使用语言。

回答

1

将对象传递给委托构造函数。

gcnew DownloadProgressChangedEventHandler(this, &Form1::DownloadProgressCallback); 
2

一个成员函数的委托,将宣布(形式内):

myWebClient->DownloadProgressChanged += gcnew DownloadProgressChangedEventHandler(this, &Form1::DownloadProgressCallback); 

基本上,第一个参数是所述成员函数定义的对象之一。在这种情况下,this应该工作。

相关问题