C#中:如何防止主要形式的太早展示 [英] C#: How to prevent main form from showing too early

查看:144
本文介绍了C#中:如何防止主要形式的太早展示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的主要方法,从我做起的主要形式和往常一样:

In my main method, I start the main form as usual:

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new MainForm());

在主要形式负载的东西我有以下的,这将要求用户登录和东西

In the main forms load thing I have the following, which will ask the user to log in and stuff.

        using (loginForm)
        {
            DialogResult r = loginForm.ShowDialog();
            switch (r)
            {
                case DialogResult.OK:
                    break;
                default:
                    Application.Exit();
                    return;

            }
        }



我的问题是主要形式显示在后台,我想它,好...不是。直到登录就可以了。我应该怎么办呢?该Application.Run()方法说出来会自动显示形式。是否有启动的主要形式,而不显示它的另一种方式?还是我设置可见假在主窗体的构造函数,然后回到真正当登录完成后,或类似的东西?什么是做这样的事情的推荐的方法?登录表单的意图就像是一个组合的闪屏和登录。因此,首先它加载,并设置了一些不同的东西,然后它告诉登录用户。

My problem is that the main form shows up in the background, and I want it to, well... not. until the login is ok. How should I do this? The Application.Run() method say it automatically shows the form. Is there an alternative way of starting the main form without showing it? Or do I have to set visible to false in the constructor of the main form, and then back to true when log in is done, or something similar? What is the recommended way of doing something like that? The login forms intention is like a combined splash screen and login. So first it loads and sets up some different things, and then it tells the user to login.

推荐答案

而不是:

Application.Run(new MainForm());



尝试:

try:

LoginDialog // the class that handles login UI
  login = new LoginDialog ();

if (login.ShowDialog () == DialogResult.OK)
{
   // check credentials
   // if credentials OK
   Application.Run(new MainForm());
}



的ShowDialog 方法是一个阻塞调用,程序将停止,直到对话框响应关闭用户输入 - 通过按确定按钮或取消按钮

The ShowDialog method is a blocking call, the program will halt until the dialog is closed in response to user input - by pressing an 'OK' button or 'Cancel' button.

这篇关于C#中:如何防止主要形式的太早展示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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