How to connect 2 CLR forms with a button (Visual C++)

Eman49 21 Reputation points
2021-12-06T03:42:05.367+00:00

Hey! I could not find how to do this any where all the results where for C#. Does any one know how to do this? Thanks for reading :)

(what I mean is open another form)

Developer technologies | Windows Forms
Developer technologies | C++
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,681 Reputation points
    2021-12-06T06:12:07.487+00:00

    You add :

    #include "MyForm2.h"
    

    then

    CLR_Test::MyForm2^ form2;
    form2 = (gcnew CLR_Test::MyForm2());
    form2->Show();
    

    (where CLR_Test is the namespace)

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. YujianYao-MSFT 4,296 Reputation points Microsoft External Staff
    2021-12-06T06:06:31.96+00:00

    Hi @Eman49 ,

    You could add code to the button. The following code uses the button to call out a blank dialog box. You could use the same method to call out the dialog box you designed. This code is written in MyForm.h, and the Form2 in the code is a dialog box that I customize. Hope it helps.

    #include"Form2.h"  
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {  
      
     Form2 ^ ff=gcnew Form2();  
     ff->Show();  
      
     }  
    

    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.

    2 people found this answer helpful.
    0 comments No comments

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.