Visual Studio 2012 在C++/CLI (C++ .Net) 在創建專案時並不會出現Visual Studio 2010之前的Windows Form 樣板選項,所以在這裡將以Console mode main()運行Form類別。
1.打開Visual Studio 2012 後點選CLR主控台模式
1.Create new CLR ConsoleApplication project
2.在專案內新增Windows Form類別
2.Add new Class and select Windows form in the project
3.此時專案將會新增一個Form
3.Now, have a new form in the project
4.在專案屬性>連結器>進階>進入點 輸入main意即程式將以main()函式運行
4.At Project>Property>Linker>Advanced>Entry keyin main,the app will start run in main()
5.在專案屬性>連結器>系統>子系統>Windows (/SUBSYSTEM:WINDOWS)
5.At Project>Property>System>Subsystem>Windows (/SUBSYSTEM:WINDOWS)
6.在ConsoleApplication1.cpp程式內輸入
6.Keyin program in ConsoleApplication1.cpp
#include "stdafx.h"
#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
ConsoleApplication1::MyForm form1;
Application::Run(%form1);
return 0;
}
7.編譯過後將得到一個Windows Form
7.Now, you get a form