[英]c# display windows form from console application
我正在研究控制台应用程序,我目前在我的项目中创建了一个Windows窗体(名称:Fcon),有没有可能的方法从控制台显示fcon?
The easiest option is to start a windows forms project, then change the output-type to Console Application. 最简单的选择是启动Windows窗体项目,然后将输出类型更改为控制台应用程序。 Alternatively, just add a reference to System.Windows.Forms.dll, and start coding: 或者,只需添加对System.Windows.Forms.dll的引用,然后开始编码:
using System.Windows.Forms;
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.Run(new Form()); // or whatever
}
The important bit is the [STAThread] on your Main() method, required for full COM support. 重要的一点是Main()方法上的[STAThread],这是完全COM支持所必需的。
Another way : 其他方式 :
using System.Runtime.InteropServices;
private void Form1_Load(object sender, EventArgs e)
{
AllocConsole();
}
[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool AllocConsole();
If you research this topic , just on Google you can find so much way to implement your question : my suggest is to try some method and verify what is more adapt to you. 如果您研究这个主题,只需在Google上,您就可以找到很多方法来实现您的问题:我的建议是尝试一些方法并验证哪些更适合您。
i have found other solution 我找到了其他解决方案
testform tf = new testform(); tf.Show();
just created forms object in main 刚刚在main中创建了表单对象
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.