2012-06-18 45 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應該工作。

相關問題