什么是打开一个新的形式和关闭电流/第一种形式的推荐的方法? [英] What's the recommended way to open a new form and close the current/first form?

查看:212
本文介绍了什么是打开一个新的形式和关闭电流/第一种形式的推荐的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立具有初始形式登录,如果用户被授权这种形式(登录)应该关闭,应用程序主要形式应该打开的应用程序。



我检查所以的问题,这将有助于我发现很多相关的问题,但我想不出我应该使用哪种技术,所以我在这里问。什么是推荐的方式来打开一个新的形式和关闭电流?



我看到一些人所建议的OP创建一个新的线程和其他人所推荐的用法向导(我不知道它是什么,但如果最好的办法,请给我一些资源研究)。



我试图做到这一点通过关闭第一和打开第二,但在应用程序关闭。



这个指的是第一种形式。

  this.Close(); 
FormSecond F =新FormSecond();
f.Show();


解决方案

如果用户授权此表(登录)应该关闭,应用程序主要形式应打开。




建议1号,2号和3强注明为< STRONG>不可以做到这一点。加上你自己的身份验证层的Windows已经提供了一个从来不是一个错误。你会的从不的得到它的安全和行之有效的Windows登录。并有严重的安全隐患,用户将重新使用自己的登录密码。如果您需要超越Environment.UserName和用户所属那么你就可以得到从System.DirectoryServices命名空间的域控制器组登录任何额外的信息。



但你会抛出谨慎的风。样板解决办法是修改Program.cs中Main()方法和使用的ShowDialog()来显示一个登录表单。这应该返回DialogResult.OK时登录是好的,DialogResult.Cancel如果事实并非如此。您可以使用这样的:

  [STAThread] 
静态无效的主要(){
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault(假);使用(VAR登录=新LoginForm的()){
如果(!login.ShowDialog()= DialogResult.OK)返回
;
}
Application.Run(新Form1的());
}


I'm building an application that have a initial form for login and if the user is authorized this form (login) should close and the application main form should open.

I was checking the SO for questions that would help and I found a lot of related questions, but I could not figure out which technique should I use, so I'm here asking. What is the recommend way to open a new Form and close the current?

I saw that some people recommended the OP to create a new thread and others recommended the usage of a "wizard" (I don't know what it is, but if that the best way please give me some resources to study).

I've tried to do it by closing the first and opening the second, but the application closes.

this is referring to the first form.

this.Close();
FormSecond f = new FormSecond();
f.Show();

解决方案

if the user is authorized this form (login) should close and the application main form should open.

Recommendations number 1, 2 and 3 strongly state to not do this. Adding your own authentication layer to the one that Windows already provides is never not a mistake. You will never get it as secure and well tested as the Windows login. And there's a serious security risk, users will re-use their login password. If you need any extra info for a login beyond Environment.UserName and the groups the user belongs to then you can get that from the domain controller with the System.DirectoryServices namespace.

But you'll throw that caution to the wind. The boilerplate solution is to modify the Main() method in Program.cs and use ShowDialog() to display a login form. Which should return DialogResult.OK when the login is good, DialogResult.Cancel if it is not. You use it like this:

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

这篇关于什么是打开一个新的形式和关闭电流/第一种形式的推荐的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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