Reputation: 565
I have a simple windows form, and a label, from another class I have a loop and I want that every cycle loop the Text propriety of label in form class change, but I can't access it, I tried to make it public but nothing to do.
So how can I change label text from another class?
Upvotes: 0
Views: 656
Reputation: 12890
Pass the label as a parameter for form2 constructor, then do what you want on it.
Something like this:
#include"form2.h"
class form1{
private: Label^ form1Labl;
private: System::Void button1_Click{
form2^ form2Obj= gcnew form2(form1Labl);
form2Obj->Show();
}
};
and in form2 class:
class form2{
private: Label^ lableObj;
form2(Label^ l){
lableObj=l;
}
// rest of your code to change lableObj->Text propriety.
};
Upvotes: 2