Windowsform landing form

zhaozj2021-02-12  136

In the C # version of the 9CBS Forum, some people often ask how to create logins, many people think that multithreading should be used. In fact, you don't need to use multiple threads at all. Below, I will write the whole process in detail to help beginners.

Suppose you have a work of Wondowsform applications, and already have a main form, named Form1 (ie, the form where the program entry point is located)

1. Add a form, this form will be your landing form.

My example form is like this, the text in TextBox is its name.

2, next to Form2, which is added to the code view of this landing form

PRIVATE BOOL ISLOGIN = FALSE;

The front of its constructor is added. This thing we have to use.

Then add an attribute

Public Bool Islogin

{

get

{

Return this.islogin;

}

}

3. Add your own verification code in the Click event processing method of the login button, which can be a read database or other method. Here, I will give a simplest example.

IF (this.txtuserid.text == "reezak" && this.txtpassword.text == "9cbs")

{

THIS.ISLOGIN = TRUE;

THIS.CLOSE (); // Landing successfully closed login form

}

Else

{

MessageBox.show ("Invalid User Or Password, Try Again!");

}

4, in the main method in the main form, change the code to

FORM2 F2 = New Form2 ();

F2.showdialog ();

IF (f2.login == true)

{

Application.run (New Form1 ());

}

5, finally, say the problem of that two buttons. You can't set the DialogResult of the login button to "OK" (preferably set to none, anyway, we customize). We have this.close () in its Click event processing method, so we don't need it.

There are two ways to the Cancel button. The most convenient is to set it DialogResult to Cancel. If set to none, add a Click event processing method, which is in this.close ();

Just like this, the login form is very simple, is it simple? ^ _ ^

转载请注明原文地址:https://www.9cbs.com/read-6261.html

New Post(0)