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 ...
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.
This indicates that no control with the given name was found.
Keep in mind that the name of the control is not necessarily the same as its ID in the designer. Check the actual name for the one you are using to find it.
You can always try static forms, D