Drag the 1 Label controls from the toolbox on the left side to the design form, then copy the 1 label controls vertically, and then modify the Text property of the 2 label controls, respectively, to user name:, password.
Drag and drop two TextBox controls from the Toolbox to the right of the corresponding label control, TextBox2 (password) Properties PasswordChar the * password will be * hidden
Continue dragging two button controls from the Toolbox to the form, and change the "Text" property to "Login" and "Cancel" respectively.
Double-click the Login button control to automatically add the Click event, and then change the event code to the following:
private void Button1_Click (object sender, EventArgs e)
{
String name = TextBox1.Text;
string password = TextBox2.Text;
Name = name. Trim (); A space does not affect
Password = password. Trim ();
if (name. Equals ("Zhansan") &&password. Equals ("1111"))
{/*messagebox.show ("welcome!"); */
Form2 f = new Form2 ();
F.show ();
This. Hide ();
}
Else
{MessageBox.Show ("false!");
}
}
Also double-click the Cancel button control with the mouse to automatically add the Click event, and then change the event code to the following:
private void Button2_Click (object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = null;
Textbox1.focus ();
This. Close ();
}