且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在VS2012中创建一个C ++ / CLI Winforms应用程序?

更新时间:2022-12-23 21:36:55

这是一个不太明确的提示,他们希望你停止创建C ++ / CLI Winforms应用程序。管道仍然到位,至少VS2012和VS2013。

It is an unsubtle hint that they want you to stop creating C++/CLI Winforms applications. The plumbing is still in place however, at least for VS2012 and VS2013. This might not be the case in a future one.

您可以通过以下步骤将CLR控制台应用程序转换为Winforms应用程序:

You can turn a CLR console application into a Winforms application with these steps:


  • 从文件+ New +项目,CLR节点,CLR控制台应用程序开始

  • 项目+添加新项目,UI节点, / li>
  • 项目+属性,链接器,系统,子系统= Windows

  • 项目+属性,链接器,高级,入口点=主
  • $ b

更改预生成的.cpp文件,如下所示:

Change the pre-generated .cpp file to look like this:

#include "stdafx.h"
#include "MyForm.h"

namespace ConsoleApplication45 {    // Change this!!
    using namespace System;
    using namespace System::Windows::Forms;

    [STAThread]
    int main(array<System::String ^> ^args)
    {
        Application::EnableVisualStyles();
        Application::SetCompatibleTextRenderingDefault(false); 
        Application::Run(gcnew MyForm());
        return 0;
    }
}

注意,您需要更改命名空间名称到您的项目名称。按F5进行测试。一旦一切都结束,您就可以将表单设计为正常。

Note that you'll need to change the namespace name to your project name. Press F5 to test. You can design the form as normal once everything checks out.