代码示例1
//Set Label.
this->TextLabel1= (gcnew System::Windows::Forms::Label());
代码示例2
//When Button Clicked....
TextLabel1->Text = "Button has been pressed";
如何在Form的代码之外引用(+更改)已设置的Label。例如。另一个cpp或头文件?
答案 0 :(得分:0)
您可以做的一件事是打破封装,通常是一件坏事,并将TextLabel1设置为公开。
因此
private: System::Windows::Forms:Label^ TextLabel1;
变为
public: System::Windows::Forms:Label^ TextLabel1;
现在您可以从调用代码中更改TextLabel1:
Form1 ^form = gcnew Form1();
form->TextLabel1->Text = "Text has been changed from the outside.";
Application::Run(form);