Modifying controls with Form.Controls
I am passing a form reference to a class. In this class, I figured I could use formRef->Controls["controlName"]
to access the properties of the control.
This works for multiple shortcuts, but on the button I get "Object reference not set to object instance". when i try to change the Text property.
Help or explanation appreciated ...
0
source to share
3 answers
I did this and it works. It might be more secure, since I can check if the control actually exists ...
array<Control^>^ id = myForm->Controls->Find("myButton", true);
id[0]->Text = "new text";
I think the reason it breaks is because the button is on a different panel. I didn't think about it when I wrote. The new solution will also search for all children, so this is an improvement.
0
source to share