如何停止在 c# windows 窗体中加载窗体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5987512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:50:36  来源:igfitidea点击:

How to stop a form from loading in c# windows forms

c#windowsformsform-load

提问by user626660

I've a windows form application where it ask the user to login before loading the entire form. If the user cancel the login then i've to stop the form loading and quit the application. In cancel_Click() method im calling this.Close(), but it is generating exception at Application.run(new Form1());. I treid with this.Dispose() and Application.exit() also but didnt worked. Please help me

我有一个 windows 窗体应用程序,它要求用户在加载整个窗体之前登录。如果用户取消登录,那么我必须停止加载表单并退出应用程序。在 cancel_Click() 方法中,我调用了 this.Close(),但它在 Application.run(new Form1()); 处产生了异常。我也尝试过 this.Dispose() 和 Application.exit() 但没有奏效。请帮我

Thanks in Adv.

感谢 Adv。

采纳答案by Alex Aza

    public static void Main()
    {
        using (var signInForm = new SignInForm())
        {
            if (signInForm.ShowDialog() != DialogResult.OK)
                return;
        }
        Application.Run(new MainForm());
    }

回答by Dulini Atapattu

The following link might help you solve the problem:

以下链接可能会帮助您解决问题:

C#: How to prevent main form from showing too early

C#:如何防止主窗体过早显示

Hope this helps...

希望这可以帮助...