Up

Programming in Visual C++/CLR 2012

Creating a Windows form application

How to use Visual Studio 2015 is explained at this website.

You can create a new windows form application in Visual C++/CLR 2013 essentially in the same way as explained below.

A simple graphics program is prepared at this website.

How to use GUI components of Visual C++/CLR is explained at this website.

How to copy a form is explained at this website.

 

Creating a new windows form application in Visual C++/CLR (.NET programming) consists of the following three steps:

1.     Prepare a new form.

2.     Write simple codes to present the form.

3.     Set project properties to disable the console window (optional).

The three steps are explained below.

 

1.     Prepare a form.

Start Visual Studio 2012, and select the menu �gFILE|New Project�h(Figure 1).

Figure 1

 

The new project dialog box will appear (Figure 2). Select the template �gVisual C++|CLR|CLR Empty Project�h.

Figure 2

 

If you want to change the Name, Location or Solution name, you can set them as you like.

Click OK button, then the new project will be created (Figure 3). Select the menu �gPROJECT|Add New Item�h.

Figure 3

 

�gAdd New Item�h window will be presented (Figure 4).  Select item �gVisual C++|UI|Windows Form�h and click Add button.

Figure 4

 

Form designer window will be presented (Figure 5).

If you want to add some components on the form, click Toolbox tab.

Figure 5

 

Click the lying pin (Figure 6).

Figure 6

 

The form designer window will be reappear (Figure 7).

If you want to put a button on the form, copy the Button on the form by click and drag. Double click the button on the form to prepare an event handler.

Figure 7

 

Event handler button1_Click will be automatically prepared (Figure 8).

Figure 8

 

In Figure 9, �gthis->Close();�h is inserted, so the form will be closed when the button is clicked.

Figure 9

 

2.     Write simple codes to present the form.

Select the menu �gPROJECT|Add New Item�h. �gAdd New Item�h window will appear (Figure 10).

Figure 10

 

Choose the template �gVisual C++|Code|C++ File (.cpp)�h, then click Add button.  The source code file will be prepared (Figure 11).

Figure 11

 

Write the following codes (Figure 12):

 

#include "MyForm.h"                    //            The header file of the form

using namespace Project1;            //            The name of the namespace in MyForm.h

[STAThreadAttribute]                   //            Run this program in STA mode

int main(){

                                          MyForm fm;                     //            The form to be created and shown

                                          fm.ShowDialog();             //            Show the form

                                          return 0;

}

 

Figure 12

 

The included file �gMyForm.h�h, namespace �gProject1�h and ref class name �gMyForm�h correspond to those for the window form to be presented (Figure 13).

Figure 13

 

After you finished the above work, click �gBUILD|Build Solution�h menu (Figure 14).

Figure 14

If Build succeeded (Figure 15), then press the function key F5 to run the program.

Figure 15

 

A console window will appear (Figure 16).

Figure 16

 

Then the form will appear (Figure 17).

Figure 17

 

 

3.     Set project properties to disable the console window.

If you don�ft want the console window to appear, set the two properties of the project, SubSystem and Entry Point, as follows.

 

Click menu �gPROJECT|(project name) Properties�h (Figure 18).

Figure 18

 

Property Pages window will appear (Figure 19). Select �gConfiguration Properties|Linker|System�h, then Click cell �gSubSystem�h

Figure 19

 

A button will appear at the right end of the cell (Figure 20).

Figure 20

 

Click the button, then a list of values will be presented (Figure 21).

Figure 21

 

Select �gWindows (/SUBSYSTEM:WINDOWS)�h, then push Apply button (Figure 22).

Figure 22

 

Next, Select �gLinker|Advanced�h, then property �gEntry Point�h will be shown (Figure 23).

Figure 23

 

As �gEntry Point�h value, enter the same name �gmain�h as in the source code file, then push Apply button (Figure 24).

Figure 24

 

Click OK button.

After the above setting of the two properties of the project, the console window will not appear when the program starts.

 

Yasuharu Okamoto

Up