2010-11-30 9 views
3

今回はC++ 9(VS2008)で "System :: Object^sender"を表すコントロール型にキャストしようとしています。C++ 9 :: "System :: Object^sender"を制御型にキャストする

これは、特にTextBox_TextChangedイベント関数にあります。

これはC#でうまく動作することが分かっていますが、C++で試してみるとエラーが発生し、C++の同等機能を見つけることができません。

エラーが発生しているコード。 。 。

System::Void txtEmplNum_TextChanged(System::Object^ sender, System::EventArgs^ e) 
{ 
    TextBox thisBox = sender as TextBox ; 
} 

エラーが発生します。 。 。

Error 1 error C2582: 'operator =' function is unavailable in 'System::Windows::Forms::TextBox' c:\projects\nms\badgescan\frmMain.h 673 BadgeScan 

任意のアイデアをお待ちしています。

ありがとうございます!

答えて

7

私はあなたがこれを試してみたいと思うかもしれません:

System::Void txtEmplNum_TextChanged(System::Object^ sender, System::EventArgs^ e) 
{ 
    TextBox^ thisBox = safe_cast<TextBox^>(sender); 
} 
+0

Right On !!! ありがとうございました! –

0

あなたは上記のコードは、C++ではありません。 C++には "as"キーワードはありません。このメソッドはC++で正しく書かれていますが、コードブロックが間違っています。

System::Void txtEmplNum_TextChanged(System::Object^ sender, System::EventArgs^ e) 
{ 
    // This is not C++. 
    TextBox thisBox = sender as TextBox; 

    // This is C++ as already stated above. 
    TextBox^ tb = safe_cast<TextBox^>(sender); 

    // Or you can just do this if you don't need a handle beyond 
    // this line of code and just want to access a property or a method. 
    safe_cast<TextBox^>(sender)->Text = "Some Text"; 
} 
関連する問題