troubleshooting Question

Modify Windows Form from another after Application::Run() C++

Avatar of johnny_device
johnny_device asked on
.NET ProgrammingVisual C++.NETMicrosoft Development
11 Comments1 Solution852 ViewsLast Modified:
This question relates to 'Microsoft Visual C++ Express'
Windows Forms application
-------------------------------------------------------------------------
I have a program with two Forms.  For Form1 to be able to modify Form2, I have instantiated an object of the Form2 Class within the Form1 Class, like this:
.........................................................................................
 public ref class Form1 : public System::Windows::Forms::Form
  {
    static Form2 ^ Form2Obj = gcnew Form2();
    public:      
      Form1(void)
      {
        InitializeComponent();
        .......... etc.
.........................................................................................
(thanks to RV for telling me about this, but I clearly still don't "get it")

I thought I'd be high and dry then, and be able to modify Form2 from Form1 like this:
Form2Obj->label1->Text = "TEST 1"; (for example).
However, this is only fine so long as I don't need to modify Form2 after it is run as an application in a separate thread, or after the dialogue is shown.  For example, if I do this:
Form2Obj->label1->Text = "TEST 1";
Form2Obj->ShowDialog();
Form2Obj->label1->Text = "TEST 2";
, then the Form2 window shows 'TEST 1' ( 'TEST 2' does not show up on the label Text).

How do I update the fields on Form2 dynamically, after Application::Run or ShowDialog?  Do I need to set up some event-driven dialogue between the two Forms?

What I want to achieve is to have Form1 take care of network connections; Form2 to run in a separate Thread and accept user input; functions in Form1 to be able to update the Form2 GUI dynamically as network events occur.


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 11 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 11 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros