开发者

Create another windows form and link two with each other

开发者 https://www.devze.com 2023-03-12 00:02 出处:网络
I\'m using visual studio 2008 c# . I want to make a login page with username, password and login buttion, and the application form this is 开发者_StackOverflow中文版another form if the username and pa

I'm using visual studio 2008 c# . I want to make a login page with username, password and login buttion, and the application form this is 开发者_StackOverflow中文版another form if the username and password were true it should link to the other winform that has the interface.


See if this helps you get started 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:

    Application.EnableVisualStyles();    
    Application.SetCompatibleTextRenderingDefault(false);
    bool loginSuccessful;
    using (LoginForm loginDialogue = new LoginForm())
    {
        loginSuccessful = (loginDialogue.ShowDialog() == DialogResult.OK);
    }
    if (loginSuccessful)
    {
        Application.Run(new Form1());
    } 
    
  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.

0

精彩评论

暂无评论...
验证码 换一张
取 消