如何将 .NET 控制台应用程序转换为 Winforms 或 WPF 应用程序 [英] How do I convert a .NET console application to a Winforms or WPF application

查看:22
本文介绍了如何将 .NET 控制台应用程序转换为 Winforms 或 WPF 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常从一个简单的控制台应用程序开始尝试一个想法,然后创建一个新的基于 GUI 的项目并复制代码.有没有更好的方法?我可以轻松转换现有的控制台应用程序吗?

I frequently start with a simple console application to try out an idea, then create a new GUI based project and copy the code in. Is there a better way? Can I convert my existing console application easily?

推荐答案

只需添加一个新的Winform,将以下代码添加到您的Main:

Just add a new Winform, add the following code to your Main:

    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());

另外,请确保 [STAThread] 属性在您的 Main 函数上方声明,以指示您的 Windows 应用程序将使用的 COM 线程模型(更多关于 STAThread 这里).

Also, be sure the [STAThread] attribute is declared above your Main function to indicate the COM threading model your Windows application will use (more about STAThread here).

然后右键单击您的项目并选择属性并将输出类型"更改为 Windows 应用程序,您就完成了.

Then right click your project and select properties and change the "Output type" to Windows application and you're done.

在 VS2008 中要更改的属性是应用程序类型

In VS2008 the property to change is Application type

这篇关于如何将 .NET 控制台应用程序转换为 Winforms 或 WPF 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆