Add a Form to a Project

srfpala 111 Reputation points

Using VS2019 VC++ under Win10 building CppCLR_WinformsProject.
Project Loads and Builds as expected.
I add a button to form1 and test it.... OK
Now when I click the button I'd like to display another form - Form2.
I think the new form should be a new item Thus Add new item seems logical ?
But Form is not shown. I see Code, Formatting , Data and others.
What should I do ?

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,827 questions
0 comments No comments
{count} votes

6 answers

Sort by: Most helpful
  1. WayneAKing 4,921 Reputation points

    Where are you selecting that option? Describe the steps - menus used, etc.

    I'm not using VS2019, but in VS2017 for a C++ WinForms app I would
    usually go to the menus:

    Project->Add New Item->UI->Windows Form

    • Wayne
    0 comments No comments

  2. srfpala 111 Reputation points

    With Form1.h [Design] visible, I also try
    Project | Add New Item and see
    Property Sheets,Test, HLSL Graphics ,Online
    Note that there is no UI->Windows Form

    0 comments No comments

  3. WayneAKing 4,921 Reputation points

    In the Properties for the project make sure that you have

    Common Language Runtime Support (/clr)

    selected under

    General->Common Language Runtime Support

    • Wayne
    0 comments No comments

  4. Kyle Wang 5,531 Reputation points

    To add a new form in CppCLR_WinformsProjekt1 VS2019, here is a workaround maybe you can refer to.

    First, right click "Headerdateien" and select "Add/New item...".


    Click tag "UI", choose "Windows Form" and add it.


    Now maybe you will get an error as below.


    Just close it and add the following code to the MyForm1.cpp:

    using namespace System;  
    using namespace System::Windows::Forms;  
    void Main(array<String^>^ args) {  
        CppCLR_WinformsProjekt1::MyForm1 form;  
        Application::Run(% form);  

    Then save it and close the Visual Studio, then reopen the Project and build/run it.

    You will see the "MyForm1.h" in "Solution Explorer".


    0 comments No comments

  5. srfpala 111 Reputation points

    Thank you KyleWang
    I tried your suggestion but errors resulted in these two lines of code:
    CppCLR_WinformsProjekt1::MyForm1 form;
    Application::Run(% form);
    // -------------------------------Errors follow----------
    name followed by :: must be a class ....
    expected a ';'
    identifier 'form' is undefined
    // -----------------------------------