How to modify properties of winforms objects at runtime? (C++/CLI)
Hypothetical:
There is a text box with the default value of "test" (this->textBox1->Text = L"test";
) and, at runtime, the value of the text property is set to "modified" by a statement in main().
The cold, hard truth:
This doesn't seem to be possible because the object is private
. Also there is a co开发者_JAVA百科mment in the form header that says it's a dumb idea to modify things so making it public is impossible.
The questions:
Am I going at this in the completely wrong way?
What is the proper way to modify the properties of form objects at runtime?
If, I were to use WPF would this avoid this confusion all together? It's not an option but i'm curious.
Thanks!
Provide public wrapper methods in your derived form class that manipulate the form controls, and call them from the other classes.
public ref class MyForm: Form
{
//...
public:
void SetTextOfTextBox1(System::String ^t)
{
this->textBox1->Text=t;
}
}
And in "main":
// ...
MyForm ^f = gcnew MyForm();
// ...
f->SetTextOfTextBox1("modified");
精彩评论