VB version here.

Here are some simple steps to create login functionality in your WinForms app.

1. Create a new WinForms project.
2. Add a new form to act as the Login dialogue.
3. Open the Program.cs code file.
4. Change the body of the Main method to the following:
CSharp Code:
  1. Application.EnableVisualStyles();
  2. Application.SetCompatibleTextRenderingDefault(false);
  3.  
  4. bool loginSuccessful;
  5.  
  6. using (LoginForm loginDialogue = new LoginForm())
  7. {
  8.     loginSuccessful = (loginDialogue.ShowDialog() == DialogResult.OK);
  9. }
  10.  
  11. if (loginSuccessful)
  12. {
  13.     Application.Run(new Form1());
  14. }
5. Add the logic to your Login form to validate the credentials supplied by the user. You may like to use this as a basis.
6. If the login succeeds set your Login dialogue's DialogResult property to OK. If the user presses the Cancel button or fails to login within a prescribed maximum number of attempts then set the DialogResult to something else.

If the user logs in successfully the app will start normally, otherwise it will exit without ever creating a main form.