Make CLR Windows Form Project by C++/CLI in Visual Studio 2019

| Aug 7, 2021 min read

因為公司的 Debug UI 是使用 C++/CLI 去做的,簡單紀錄專案怎麼建立。

1. 在 Visual Studio 2019 安裝 C++/CLI

file

2. 建立 CLR WinForm 專案

建立新專案 – 選擇 CLR 空白專案 (.NET Framework)

file

設定專案名稱、路徑及 .NET 架構

file

選擇建立之後會進入開發介面

file

3. 設定桌面應用程式設定

對專案按右建 » 屬性 » 進入屬性設定頁面

file

組態屬性 » 連結器 » 系統 » 子系統 » 選擇 Windows

file

組態屬性 » 連結器 » 進階 » 進入點 » 輸入 main

file

4. 新增 UI 項目

對專案按右建 » 加入 » 新增項目

file

新增項目 » Visual C++ » UI » Windows Form

file

5. 重新啟動 Visual Studio 2019 並開啟專案

開啟標頭檔 » MyForm.h » 出現設計視窗

file

6. 在 MyForm.cpp 新增主函式 main()

#include "MyForm.h"

using namespace System;
using namespace System::Windows::Forms;
[STAThreadAttribute]
void main(array<String^>^ args) {
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    MyProject::MyForm form;  // MyProject 需根據專案名稱進行替換
    Application::Run(% form);
}

Refer

comments powered by Disqus