C++ 9 ::将"System :: Object ^ sender"转换为Control类型

A C*_*orm 3 textbox c++-cli visual-studio-2008

这次在C++ 9(VS2008)中我试图将"System :: Object ^ sender"转换为它所代表的Control类型.

这特别是在TextBox_TextChanged事件函数中.

我知道这在C#中工作得很好,但是当我在C++中尝试它时我遇到了错误,我似乎无法找到C++的等价物.

给我错误的C++代码...

System::Void txtEmplNum_TextChanged(System::Object^  sender, System::EventArgs^  e)
{
    TextBox thisBox = sender as TextBox ;
}
Run Code Online (Sandbox Code Playgroud)

并导致错误...

Error   1   error C2582: 'operator =' function is unavailable in 'System::Windows::Forms::TextBox'  c:\projects\nms\badgescan\frmMain.h 673 BadgeScan
Run Code Online (Sandbox Code Playgroud)

欢迎任何想法.

谢谢!

mes*_*ger 7

我想你可能想试试这个:

System::Void txtEmplNum_TextChanged(System::Object^  sender, System::EventArgs^  e) 
{ 
    TextBox^ thisBox = safe_cast<TextBox^>(sender); 
} 
Run Code Online (Sandbox Code Playgroud)