如何运行控制台应用程序的一个WinForm? [英] how to run a winform from console application?
本文介绍了如何运行控制台应用程序的一个WinForm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建,执行和从控制台应用程序中控制一个winform?
How do I create, execute and control a winform from within a console application?
推荐答案
最简单的方法是启动Windows窗体项目,然后更改输出类型控制台应用程序。此外,只需添加对System.Windows.Forms.dll的引用,开始编码:
The easiest option is to start a windows forms project, then change the output-type to Console Application. Alternatively, just add a reference to System.Windows.Forms.dll, and start coding:
using System.Windows.Forms;
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.Run(new Form()); // or whatever
}
最重要的一点是 [STAThread]
在的Main()
方法,全面支持COM要求。
The important bit is the [STAThread]
on your Main()
method, required for full COM support.
这篇关于如何运行控制台应用程序的一个WinForm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文