开始在C#控制台项目的一种形式? [英] Starting a form in C# console project?

查看:132
本文介绍了开始在C#控制台项目的一种形式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目是一个控制台客户端。我开始在控制台,然后显示形式。我用下面的code显示空白表格(我将在后面添加控件)给用户。但形式显示出来,但它被卡住(未激活)。我该怎么办?

  Console.WriteLine(启动形式);
Console_Client.Main的MainForm =新的Main();
mainform.Show();
到Console.ReadLine();
 

解决方案

尝试的ShowDialog()

现在的问题是,你不运行的消息循环。有两种方法来启动之一。 的ShowDialog()已一体的综合性,以便将工作。另一种方法是使用 Application.Run(),无论是在显示()来电或形式为参数。

  1. 的ShowDialog()

      mainform.ShowDialog();
     

  2. Application.Run()不形:

      mainform.Show();
    Application.Run();
     

  3. 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.

  1. ShowDialog():

    mainform.ShowDialog();
    

  2. Application.Run() without form:

    mainform.Show();
    Application.Run();
    

  3. Application.Run() with the form:

    Application.Run(mainform);
    

All of these work.

这篇关于开始在C#控制台项目的一种形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆