I don't know what would be a good title for this but I'll just explain.

I have two forms. When I run my login form, my main menu form will also visible but only behind my login form. Now, you might have some idea what i'm talking about? . My main menu form cannot be click unless the login form will be validated by inputting a username and password

You're looking to make your login form a modal form...

A Modal Form basically means that you cannot proceed with the program until the modal form's task has been performed and the form is removed by the program.

For more information on how to implement modal forms check this link.

Hope this helps :) Please remember to mark this thread solved when your issue is resolved.

it's working now but if I tried closing the login form clicking close from the title bar, the login form closes and I am able to use the other form. How could i make the close from the title bar close all the form.

You can disable the X close button on the login form. ControlBox = false.

I believe you can also code to ensure they can't do a right-click close as well but I'm not sure how to do that or if it's even necessary once you've disabled the ControlBox.

Right click is also disabled. Thanks for this.

But there's some bit of a problem. I said that there are two forms open, and I put my main menu as the startup windows form then I include in my Main_Load,

Login Login = new Login();
Login.ShowDialog();

It opens the login form but when I tried to exit using my cancel button from login form which has a code of

DialogResult dlgResult = MessageBox.Show("Are you sure?", "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dlgResult == DialogResult.Yes)
            {
                Main Main = new Main();
                Main.Close();
                this.Close();
            }

The login form closes but not the main menu form. How to do this?

By using Main Main = new Main(); , you've made a new Main form. It doesn't hold reference to the other open Main form.

You are trying to close both forms which will close the application. So better use Application.Exit(); :

if (dlgResult == DialogResult.Yes)
 {
      Application.Exit();
      return;
 }
commented: That's what I get for not refreshing the thread before I post :P +1

I'm not sure if it's what you want to do per-se but have you tried (when they choose to cancel) using Application.Exit() instead of just closing the forms? I assume if they cancel login you don't want the application running any longer.

Edit: What Farooqaa said :P (I stepped away for a bit and forgot to reload the thread to see if other answers were here before I replied)
Edit 2: And now, as it's 4am here... :zzz: Don't forget to mark the thread as solved once you're done resolving your issue.

commented: :) +2

it's working. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.