Update textbox on another form - C++ Winforms

José Carlos 886 Reputation points
2022-12-13T21:20:51.787+00:00

Hi friends

I have a small C++ Winforms application. I have only two forms (form1 and form2). I being in form2, I need to update data in two textBox that are in form1.

How to do this?

Thanks.

Developer technologies C++
{count} votes

Accepted answer
  1. YujianYao-MSFT 4,296 Reputation points Microsoft External Staff
    2022-12-14T02:40:12.793+00:00

    Hi @Anonymous ,

    You need to complete the preparations in this link before implementing this function.

    Now, you need to right click on the textBox and select properties, then double click on TextChanged in the event list, this event is triggered when the text property finds a change.

    270259-change1.png

    Then enter the following code to achieve your needs.

               private:  
                System::Void textBox1_TextChanged(System::Object ^ sender,  
                                                  System::EventArgs ^ e) {  
                  
                MyForm ^ form1 = (MyForm ^) Application::OpenForms["MyForm"];  
    
                  form1->txt1->Text = textBox1->Text;  
                }  
    
               private:  
                System::Void textBox2_TextChanged(System::Object ^ sender,  
                                                  System::EventArgs ^ e) {  
                  MyForm ^ form1 = (MyForm ^) Application::OpenForms["MyForm"];  
    
                  form1->txt2->Text = textBox2->Text;  
                }  
    

    RESULT:

    270311-ss.gif

    Best regards,

    Elya


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.