views:

38

answers:

1

Code Sample 1

//Set Label.
this->TextLabel1= (gcnew System::Windows::Forms::Label());

Code Sample 2

//When Button Clicked....
TextLabel1->Text = "Button has been pressed";

How do I reference (+ change) the Label that has been set, outside the Form's code. Eg. Another cpp or header file?

A: 

One thing you can do is break encapsulation, often a bad thing, and set TextLabel1 to public.

Hence

private: System::Windows::Forms:Label^ TextLabel1;

becomes

public: System::Windows::Forms:Label^ TextLabel1;

Now you can change TextLabel1 from the calling code:

Form1 ^form = gcnew Form1();
form->TextLabel1->Text = "Text has been changed from the outside.";
Application::Run(form);
Blanthor