Step 5: Displaying a Login Form

When you create a new Windows Forms application, a Login Form is automatically created for you. By default, it's a simple form with just a few controls, but you can enhance it to your heart's content! For example, here is the Login Form from the MM .NET sample application:

To display a login form at application startup, follow these steps:

  1. In the Solution Explorer, double-click your App.cs or App.vb file to open it in the design surface.

  2. Go to the Property Sheet and set the DisplayLoginForm property to True.

  3. If you are using server authentication to access your security database (which requires a user id and password), you need to specify an initial user ID and password for connecting to this database when first authenticating a user. Note that these values are only used on the initial connection to authenticate the user.

    To specify these user ID and password values:

    • In the Solution Explorer, right-click the UserLoginForm and select View Code from the shortcut menu.

    • Set the UserIDConnect and PasswordConnect properties in the constructor of the Login form.

      In C#:

      public UserLoginForm()
      {
      	this.UserIDConnect = "sa";
      	this.PasswordConnect = "MyPswd";
      
      	//
      	// Required for Windows Form Designer support
      	//
      	InitializeComponent();
      }

      And in VB .NET:

      Public Sub New()
      
         Me.UserIDConnect = "sa"
         Me.PasswordConnect = "MyPswd"
      
         '
         ' Required for Windows Form Designer support
         '
         InitializeComponent()
      
      End Sub

    Even though these code samples hard code the initial user authentication connection information at design time, you can data drive these settings, storing them in an external file and setting them dynamically at run time.

Using the HookUserAuthenticated Method

At times you may want to perform additional processing when a user has been authenticated. The HookUserAuthenticated method provides a hook into which you can place code to be executed after a user's login credentials (such as user ID and password) are authenticated. You can add an override of this method to your application-level login form and place processing code in this method.

For example, in C#:

public override void HookUserAuthenticated(object userPK)
{
	// TODO: Additional processing code
}

And in VB .NET:

Public Overrides Sub HookUserAuthenticated(userPK As Object)
	' TODO: Additional processing code
End Sub

See also:
Step 6: Displaying a Users Form


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/26/18
Comment or report problem with topic