开始在C#控制台项目的一种形式? [英] Starting a form in C# console project?
问题描述
我的项目是一个控制台客户端。我开始在控制台,然后显示形式。我用下面的code显示空白表格(我将在后面添加控件)给用户。但形式显示出来,但它被卡住(未激活)。我该怎么办?
Console.WriteLine(启动形式);
Console_Client.Main的MainForm =新的Main();
mainform.Show();
到Console.ReadLine();
尝试的ShowDialog()
。
现在的问题是,你不运行的消息循环。有两种方法来启动之一。 的ShowDialog()
已一体的综合性,以便将工作。另一种方法是使用 Application.Run()
,无论是在显示()
来电或形式为参数。
-
的ShowDialog()
:mainform.ShowDialog();
-
Application.Run()
不形:mainform.Show(); Application.Run();
-
Application.Run()
的形式:Application.Run(MainForm的);
所有这些工作。
My project is a console client. I start in the console and then display the form. I use the code below to display a blank form (I will add controls later) to the user. But the form is displayed, but it is stuck (not active). What should I do?
Console.WriteLine("Starting form");
Console_Client.Main mainform = new Main();
mainform.Show();
Console.ReadLine();
Try ShowDialog()
.
The problem is that you're not running a message loop. There are two ways to start one. ShowDialog()
has one integrated so that will work. The alternative is to use Application.Run()
, either after the Show()
call or with the form as a parameter.
ShowDialog()
:mainform.ShowDialog();
Application.Run()
without form:mainform.Show(); Application.Run();
Application.Run()
with the form:Application.Run(mainform);
All of these work.
这篇关于开始在C#控制台项目的一种形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!