After creating a Windows form, nothing happens

Ілля Корнійчук 0 Reputation points
2023-07-12T12:49:49.5366667+00:00

Here's what I do.
These are my settings in VS installer.

User's image

Then i create a project

User's image

Then i add New ItemUser's image

And select windows form

User's image

But after that, nothing is added and nothing happens, so what to do?
User's image

Developer technologies | Windows Forms
Developer technologies | C++
{count} votes

2 answers

Sort by: Most helpful
  1. Reza Aghaei 4,986 Reputation points MVP Volunteer Moderator
    2023-07-13T13:54:38.98+00:00

    I noticed C++ tag, and the project type as CLR Empty project. In this case, you need to add the entry point to your code, for example, you can follow these steps:

    1. Create an Empty CLR project (C++) (let's say Project1)
    2. Add a new Item, and from CLR templates, choose Windows Form (let's say MyForm)
    3. Open MyForm.cpp and add the following code as entry point to run the form. To do so, paste the following code in the file:
    #include "MyForm.h"
    
    using namespace System;
    using namespace System::Windows::Forms;
    [STAThread]
    
    void main()
    {
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false);
        Application::Run(gcnew Project1::MyForm);
    }
    

    Now you can press <kbd>F5</kbd> and see your form running.

    Note: The approach is pretty similar if you use a CLR console application; then it will create the entry point in the ConsoleApplication1.cpp file, and you can modify the entry point like I above.

    C++/CLI More information:

    C# More information:

    If you are working with C#, you may want to take a look at the following links:

    1 person found this answer helpful.

  2. Ілля Корнійчук 0 Reputation points
    2023-07-13T17:22:13.62+00:00

    My decision was to install the Visual Studio 2019 version, in which everything works well

    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.