Click to See Complete Forum and Search --> : Updating form controls outside of form file


Venturio
March 14th, 2009, 04:35 PM
Hi,

I'm new to C++ (and these forums), but I have some experience with Java, PHP and several other languages though.

I made a Windows forms application and would like to know an easy way to update the form controls of the mainform, from any cpp file, function, etc... in my project.

For example, a function (outside the form header file) should be able to update a textfield in the form, during its execution. What would be the best way to do this in C++?

In the main function, I tried this:

MainForm^ mainform = gcnew MainForm();
Application::Run(mainform);
mainform->txtUpdates->Text = "test";

But this doesn't work. Can anyone help?

Thanks in advance!

TheCPUWizard
March 14th, 2009, 04:50 PM
You are in the wrong forum. That is managed code, and belongs in the C++/CLI forum.

Please contact a moderator and ask them to MOVE your existing post (do not double post)!

cilu
March 14th, 2009, 07:49 PM
[ redirected ]

Well, when you say any, that can be a lot. If it's in the same thread, then you can provide a pointer to the main window to the class from where you want to update it. If you are in a different thread (this also works for the previous case) then you won't be able to update the controls directly, and you have to post a message to the main window, handle it in the main window class and update the controls appropriately.