C++ Visual Studio 2012 RC 中的 Windows 窗体 CLR 应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11130915/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:52:48  来源:igfitidea点击:

windows form CLR application in Visual studio 2012 RC?

c++.netvisual-studio-2008clrvisual-studio-2012

提问by Adil Chaudhry

quick question, im just trying out VS2012 and trying to make a c++.net app but for the life of me i cant find the option anymore when making a new project.

快速提问,我只是在尝试 VS2012 并尝试制作一个 c++.net 应用程序,但在我的一生中,我在制作新项目时再也找不到这个选项了。

In vs2008 it used to be under new project>visual c++> CLR>windwos form application.

在vs2008中,它曾经是在新项目>visual c++> CLR>windwos表单应用程序下。

Have they removed the option to make c++/CLR application in .net from vs2012? Or is it something i must download?

他们是否从 vs2012 中删除了在 .net 中制作 c++/CLR 应用程序的选项?或者是我必须下载的东西?

回答by Tim 't Hart

Although Microsoft removed the option to create a C++/CLI Windows Forms application, the template files are still installed. The only thing missing seems to be the .vsz files and a registration in the vcNET.vcdir file. I have recreated these files and put them up for download here.

尽管 Microsoft 删除了创建 C++/CLI Windows 窗体应用程序的选项,但仍会安装模板文件。唯一缺少的似乎是 .vsz 文件和 vcNET.vcdir 文件中的注册。我重新创建了这些文件,并把它们放在这里下载。

Install the files and you should be able to create WinForm apps in C++/CLI again.

安装这些文件,您应该能够再次在 C++/CLI 中创建 WinForm 应用程序。

回答by codegasm

Well, many people have faced this problem. Here is what I follow:

嗯,很多人都遇到过这个问题。这是我遵循的:

Create a Visual C++ --> CLR --> CLR Empty Project (Obviously you specify the Name and the Directory).

创建一个 Visual C++ --> CLR --> CLR 空项目(显然你指定了名称和目录)。

Once it gets created, right-click on the project and select "Add --> New Item".

创建后,右键单击项目并选择“添加 --> 新项目”。

Under the UI tab, select "Windows Form". Name your form and click OK. This form would get added to the project.

在 UI 选项卡下,选择“Windows 窗体”。命名您的表单并单击“确定”。此表单将被添加到项目中。

After the form gets added, copy the following code inside the YourFormName.cpp:

添加表单后,将以下代码复制到YourFormName.cpp

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

[STAThread]
void Main(array<String^>^ args)
{
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    Project1::MyForm myForm;        //NameOfProject::NameOfForm instanceOfForm;
    Application::Run(%myForm);
}

We're almost done...

我们快完成了...

Now under the Project Properties, expand the Linkersection and select "System". Under the subsystem option, choose Windows(/SUBSYSTEM/WINDOWS)

现在在项目属性下,展开该Linker部分并选择“系统”。在子系统选项下,选择 Windows(/SUBSYSTEM/WINDOWS)

Now add an entry point. Under the "Linker-->Advanced", choose "Main" as the "Entry Point"

现在添加一个入口点。在“Linker-->Advanced”下,选择“Main”作为“Entry Point”

Build and Run..Voila!!

构建并运行..瞧!

P.S.:This is only an empty form ;)

PS:这只是一个空表格;)

回答by Jesse Good

Yes, microsoft has removed the option, here is the response from microsoft (reference):

是的,微软已经删除了这个选项,这里是微软的回应(参考):

C++/CLI is a great solution for interop, but we do not recommend creating brand new UI applications using C++/CLI.

C++/CLI 是一个很好的互操作解决方案,但我们不建议使用 C++/CLI 创建全新的 UI 应用程序。

The workaround provided by the link is:

链接提供的解决方法是:

  1. Create an empty C++ solution with both 2012RC and MSVC2010 Express.
  2. Using 2010 Express, create a new WinForm App project inside the folder of the 2012RC empty solution. Close all saving.
  3. Using 2012RC and the "add existing project", add the 2010 Express-WinForm App project into the empty 2012RC solution.
  4. Right click on the project to convert it to 2012RC "format"

It works and it is simple! But I don't know all the consequences.

  1. 使用 2012RC 和 MSVC2010 Express 创建一个空的 C++ 解决方案。
  2. 使用 2010 Express,在 2012RC 空解决方案的文件夹中创建一个新的 WinForm App 项目。关闭所有保存。
  3. 使用 2012RC 和“添加现有项目”,将 2010 Express-WinForm App 项目添加到空的 2012RC 解决方案中。
  4. 右键单击项目将其转换为2012RC“格式”

它有效而且很简单!但我不知道所有的后果。

回答by qPCR4vir

Creating the template by yours self:

自己创建模板:

  1. Create an empty C++ solution with both 2012RC (New Project -> Other Project Types -> Visual Studio Solutions -> Blank Solution) and MSVC2010 Express (New Project -> Visual C++ -> Empty Project).
  2. Using 2010 Express, create a new Windows Form App project (name it “myWForm11” or so) inside the folder of the 2012RC empty solution. Close 2010 Express saving all.
  3. Using 2012RC and the "add existing project", add the 2010 Express-WinForm App project into the empty 2012RC solution.
  4. Right click on the solution to upgrade VC++ projectsto 2012RC "format"
  5. FILE -> Export Template ... -> Next> Type in Template name: "Windows Form App, C++ 2012RC" or so and some description too.
  6. Finish
  7. Close solution
  1. 使用 2012RC(新项目 -> 其他项目类型 -> Visual Studio 解决方案 -> 空白解决方案)和 MSVC2010 Express(新项目 -> Visual C++ -> 空项目)创建一个空的 C++ 解决方案。
  2. 使用 2010 Express,在 2012RC 空解决方案的文件夹中创建一个新的 Windows Form App 项目(命名为“myWForm11”左右)。关闭 2010 Express 保存所有。
  3. 使用 2012RC 和“添加现有项目”,将 2010 Express-WinForm App 项目添加到空的 2012RC 解决方案中。
  4. 右键单击解决方案将VC++项目升级为2012RC“格式”
  5. FILE -> Export Template ... -> Next> 输入模板名称:“Windows Form App, C++ 2012RC”左右以及一些描述。
  6. 结束
  7. 关闭解决方案

Now you can create WF App in 2012RC “as always” (New Project -> Installed -> Templates -> Visual C++ -> Windows Form App, C++ 2012RC).

现在,您可以“一如既往”在 2012RC 中创建 WF 应用程序(新建项目 -> 已安装 -> 模板 -> Visual C++ -> Windows 窗体应用程序,C++ 2012RC)。

It works and it is simple! But I don't know all the consequences.

它有效而且很简单!但我不知道所有的后果。

回答by user40594

I just created a new project in VS2010. Then import it into VS2013.

我刚刚在 VS2010 中创建了一个新项目。然后导入到VS2013中。

You will find the form designer doesn't always work with this. Change the source file slightly and save it. The form designer will then wok ok until you load in the project again.

您会发现表单设计器并不总是与此一起工作。稍微更改源文件并保存。然后表单设计器将正常工作,直到您再次加载项目。