Up

Visual C++ 2019/.NET FormApplication

 

Visual Studio Community 2019 can be downloaded freely from the website

https://visualstudio.microsoft.com/downloads/

To develop a Visual Studio C++ 2019/.NET Form Application, Visual Studio Community 2019 must be installed with the three options, .NET desktop development, Desktop development with C++, and C++/CLI support for v142 build tools, being checked (Figure 1). CLI (Common Language Infrastructure) is part of Microsofts .NET strategy.

Figure 1

 

After Visual Studio Community 2019 with the options marked by red rectangles in Figure 1 is installed, Start the Visual Studio. Choose Open a new project (Figure 2).

Figure 2

 

The Create a new project dialog window will be displayed (Figure 3).

Figure 3

 

Choose CLR Empty Project option. CLR (Common Language Runtime) is the runtime environment in the .NET Framework.

Click the Next button. Configure your new project dialog window will be displayed (Figure 4).

Figure 4

 

Set names of the project and solution, and a location where the solution is put. Click on the Create button. The empty solution will be shown (Figure 5).

 

Figure 5

 

Choose menu item Project|Add New Item... (Figure 6).

Figure 6

 

Add New Item dialog window will be displayed (Figure 7).

Figure 7

 

Choose the menu item Visual C++|UI, and select the item Windows Form. Click the Add button.

The selected new item Windows Form will not be displayed. Instead, the error messages will be shown (Figure 8).

Figure 8

 

Simply close the solution, choosing the menu item File|Close Solution (Figure 8).

Then, open the closed solution again (Figure 9).

Figure 9

 

This time, the added new item Windows Form is successfully displayed (Figure 10).

Figure 10

 

To display the form during execution of the program, lets see the code for the Windows Form. Choose the menu item View|Code.

Figure 11

 

Code of the Windows Form will be displayed (Figure 12).

Figure 12

 

The file name is MyForm.h, the namespace name is Project1, and the Class name is MyForm. To prepare a code, which creates an object of the Class MyForm, choose the menu item Project|Add New Item...(Figure 13).

Figure 13

 

The Add New Item dialog window will be displayed (Figure 14).

Figure 14

 

Choose the menu item Visual C++|Code, then select the C++ File (.cpp) item. Click on the Add button. The new empty code file will be added to the solution, and be displayed (Figure 15).

Figure 15

 

Write code as shown in Figure 16, to create and display the Form object.

Figure 16

 

Choose the menu item Debug|Start Debugging, or press the F5 key, to execute the project. The form will be displayed as in Figure 17.

Figure 17

 

For further development of your .NET form application, visit this website, which is written in Japanese, but may be translated into your language by Google.

In the case of Figure 17, behind the form, a console window is also displayed. If you do not want the console window, the following settings of the project are needed.

Choose the menu item Project|Project Properties (Figure 18).

Figure 18

 

In the Project Property Pages dialog windows, choose the menu item Linker|System. Click on the button at the right end of the SubSystem row.

Figure 19

 

Menu list will be shown. Select the item Windows (/SUBSYSTEM:WINDOWS). This item will be set in the cell (Figure 20).

Figure 20

 

Click on the Apply button,, and on the OK button.

To set the next setting, choose the menu item Linker|Advanced. Set Entry Point for main, the main function of the project.

Figure 21

 

Click on the Apply button, and the OK button.

After these two settings, the console window will not appear when the project is executed.

 

To learn more on development of .NET form application, visit this website.

 

Up