tags:

views:

49

answers:

3

Hi there, i'm thinking about writing a WPF program that would require login and password at the app startup. I thought about small form with two textboxes as a login form. User will have to fill in his details and then the main form of the application will be unlocked. How will you solve this?

Thanks for your answers, daemonsvk

+2  A: 

This is standard behavior for the Window.ShowDialog() call. Other windows will be disabled.

Hans Passant
A: 

I would make the initial startup form your login page and authenticate the user, if their details are correct hide the login form and show you other form.

if(user is authed)
{
    this.Hide(); //Hide the login form
    mainAppForm.Show(); //or Form.ShowDialog(); //Shows the main form
}
Chief17
A: 

The simplest way to do this is to first show (using ShowDialog, which blocks i.e. waits until the form is closed before continuing to the next line of code) the login form. If the login is successful, you dispose the login form and then show your main form; if the login fails, you end the application.

If, however, you want your main form to be visible underneath the login form (a not unreasonable requirement), then you need to first show the main form, and then display the login form (modally) from a method in the main form. In WinForms this requires some kind of hack, since you couldn't show the login form from either the main form's constructor or its Load event (as the main form won't yet be visible when the login form appears).

WPF may handle this better now.

MusiGenesis