How do I convert a .NET console application to a Winforms or WPF application(如何将 .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 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何将 .NET 控制台应用程序转换为 Winforms 或 WPF 应用程序
基础教程推荐
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
