Visual Studio 2017 - 找不到 Visual C++ Windows 窗体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44769210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio 2017 - can't find Visual C++ Windows Forms
提问by Ch3shire
So, I'm in awkward situation - I wanted to create Windows Form App using Visual Studio, but I can't find any place to create Visual C++ Windows Form template. I tried even to reinstall Visual C++, add other libraries and search answer online - no results.
所以,我处于尴尬的境地 - 我想使用 Visual Studio 创建 Windows 窗体应用程序,但找不到任何地方来创建 Visual C++ Windows 窗体模板。我什至尝试重新安装 Visual C++,添加其他库并在线搜索答案 - 没有结果。
I can of course create new Winforms in C#:
我当然可以在 C# 中创建新的 Winforms:
But not in C++:
但不是在 C++ 中:
Also, all possible modules in Visual Studio Update was checked:
此外,检查了 Visual Studio 更新中所有可能的模块:
I tried even add template from Online list:
我什至尝试从在线列表中添加模板:
What should I do next? I use Visual Studio 2017 Community Edition.
我接下来该怎么做?我使用 Visual Studio 2017 社区版。
回答by Ch3shire
Ok, I found a working way to creating Windows Forms in Visual Studio 2017.
好的,我找到了一种在 Visual Studio 2017 中创建 Windows 窗体的有效方法。
- Create new CLR Empty Project:
- 创建新的 CLR 空项目:
Add .cpp file for main function.
In project add new item from UI->Windows Forms:
为 main 函数添加 .cpp 文件。
在项目中从 UI->Windows Forms 添加新项目:
(If we didn't add main loop before the error will occur)
(如果我们没有在错误发生之前添加主循环)
- Now we can add new elements to form from the Toolbox to the left (i spent measurable time looking for that).
- 现在我们可以从左侧的工具箱中添加新元素以形成表单(我花了大量时间寻找它)。
- To run application we have to declare this instead of main function:
- 要运行应用程序,我们必须声明 this 而不是 main 函数:
Also we need to tell Visual Studio that we are making Windows Application instead of Console Application:
我们还需要告诉 Visual Studio 我们正在制作 Windows 应用程序而不是控制台应用程序:
回答by Mark Waterman
WinForms designer support for C++/CLI was droppeda long time ago in VS 2012. MS suggests using C# for your WinForms code, and only use C++/CLI if you need to interop with native code.
WinForms 设计器对 C++/CLI 的支持很久以前在 VS 2012 中就被删除了。MS 建议在你的 WinForms 代码中使用 C#,如果你需要与本机代码互操作,则只使用 C++/CLI。
And if you do end up using C++/CLI for interop, keep that layer as small as possible. It's a second-class citizen in the .NET world and isn't even mentioned in Microsoft's recent poston their language strategy.
如果您最终使用 C++/CLI 进行互操作,请将该层保持尽可能小。它是 .NET 世界中的二等公民,甚至在微软最近关于他们的语言策略的帖子中都没有提到。