What's the recommended way to open a new form and close the current/first form?

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.

FormSecond f = new FormSecond();


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:

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

Need Your Help

How to highlight a navigation menu partial according to what url the user is on?

html ruby-on-rails url navigation

I have a partial called _navigation.html.erb in my views/shared/ folder:

Android: textView doesn't show cursor

android textview

I have a textView which is configured as an EditText. But the problem is that the cursor doesn't appear when i'm pressing keys (text is written correctly).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.