打开第二个形式,而自动关闭的第一种形式 [英] Open a second form while automatically closing the first form

查看:130
本文介绍了打开第二个形式,而自动关闭的第一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了C#中的登录表单。

I created a login form in c#.

如果在用户登录使用正确的用户名和密码,并点击了登录,然后第二种形式打开。如何关闭登录表单的最后一步后?

If a user signs in with the right password and username and clicks on 'Login' then the second form opens. How do I close the login form after the last step?

推荐答案

在Program.cs中更改Main()方法来显示登录对话框。除非输入了有效的登录,不要启动消息循环。例如:

Change your Main() method in Program.cs to display the login dialog. Don't start the message loop unless a valid login was entered. For example:

static void Main() {
  Application.EnableVisualStyles();
  Application.SetCompatibleTextRenderingDefault(false);
  using (var login = new LoginForm()) {
    if (login.ShowDialog() != DialogResult.OK) return;
  }
  Application.Run(new Form1());
}

您LoginForm的,如果它检测到正确登录其DialogResult属性应该设置为OK。

Your LoginForm should set its DialogResult property to OK if it detected a proper login.

这篇关于打开第二个形式,而自动关闭的第一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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