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 应用程序
基础教程推荐
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
