Create C++ Windows Forms Application in Visual Studio 2017

Background:

From Windows Forms Application in Visual C++ ???!!!!:

"MS removed the WinForms C++/CLI template starting in either VS2012 or VS2013.  The official explanation is that they want to encourage managed desktop UI development in C# or VB and relegate C++/CLI to serve as glue between native back end code and managed UI code."

But for some reason, there are still many people who have reason to create a Windows Forms project of type C++/CLI, for these people, the following steps will show you how to start a C++/CLI Windows Forms app in Visual Studio 2017.

Environmental configuration:

Modify your Visual Studio 2017 installer and make sure your Visual Studio 2017 have installed C++ package with C++/CLR:

Create new project:

1, If you have installed all the package and components, then open Visual Studio 2017 and create a new project:

2, You need to configure some properties first, right click on the Project and choose Properties option:

Add new item:

1, Right click on the project to add a new item, select UI under Visual C++,then choose Windows Form:

In general, you will get error as below in this step:

2, Don't worry, close it and add the following code to the MyForm.cpp:

using namespace System;
using namespace System::Windows::Forms;

[STAThreadAttribute]
void Main(array<String^>^ args) {
               Application::EnableVisualStyles();
               Application::SetCompatibleTextRenderingDefault(false);
               Project1::MyForm form;
               Application::Run(%form);
}

3, After that, save it and close the Visual Studio, then reopen your Project. Note that when you reopen your Project, remember to build(or run directly) it first:

4, Now you can do your options in the form by double click MyForm.h:

转载于:https://www.cnblogs.com/jizhiqiliao/p/10071703.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值