Sei sulla pagina 1di 4

Development Software 2

Create a C++ Windows Forms Application Project using Visual Studio 2013
1 | P a g e Compiled By WH. Olivier 2014
Cape Peninsula University of Technology


The following steps will show you how to design a Windows Forms Application using C++ language in
Visual Studio 2013
Because the Windows Form Application template is not include in the 2013 version of Visual Studio, we
need to do a view things which will cause our application to function like a Windows Form Application.
These steps must be repeated every time you develop a new C++ Windows Application in Visual Studio
2013.

Step 1. Create a Windows Forms Application project.
1. On the menu bar, choose File, New, Project. The dialog box should look like this.


2. Choose Visual C++ and CLR in the Installed Templates List

3. In the Templates list, choose CLR Empty Project. Name the new Project Tutorial1 and press
OK button.

4. Add a Windows Form by selecting Project Add New Item
Development Software 2
Create a C++ Windows Forms Application Project using Visual Studio 2013
2 | P a g e Compiled By WH. Olivier 2014
Cape Peninsula University of Technology




5. Select UI under Visual C++.
Leave the Form name as given by default MyForm.h.
Then, click Add.



Development Software 2
Create a C++ Windows Forms Application Project using Visual Studio 2013
3 | P a g e Compiled By WH. Olivier 2014
Cape Peninsula University of Technology


6. We need to edit the MyForm.cpp file as follows

#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;

[STAThread]
void Main(array<String^>^ args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Tutorial1::MyForm form;
Application::Run(%form);
}
7. The System namespace provides functions to work with UI controls.
At the right-mouse click on Tutorial1, we get the Properties window.
Configuration Properties->Linker->System
Select Windows (/SUBSYSTEM:WINDOWS) for SubSystem.
Advanced->Entry Point, type in Main.
The, hit OK.
Step 2: Run Your Program (back)
To run your program
1. Use one of the following methods to run your program.
o Choose the F5 key.
o On the menu bar, choose Debug, Start Debugging.
o On the toolbar, choose the Start Debugging button, which appears as follows.
Start Debugging toolbar button
2. Visual Studio runs your program, and a window called MyForm appears. The following diagram
shows the program you just built. The program is running, and you will soon add to it.

Development Software 2
Create a C++ Windows Forms Application Project using Visual Studio 2013
4 | P a g e Compiled By WH. Olivier 2014
Cape Peninsula University of Technology



Windows Form Application program running
3. Go back to the Visual Studio integrated development environment (IDE), and look at the new
toolbar. Additional buttons appear on the toolbar when you run a program. These buttons let you
do things like stop and start your program, and help you track down any errors (bugs) it may
have. For this example, we're just using it to start and stop the program.

Debugging toolbar

4. Use one of the following methods to stop your program.
o On the toolbar, choose the Stop Debugging button.
o On the menu bar, choose Debug, Stop Debugging.
o Choose the X button in the upper corner of the Form1 window.

Potrebbero piacerti anche