C#实现用户名与密码登录
编写一个C#窗体应用程序,能够输入用户名、密码,并进行登录、取消等操作。
登录界面设计
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace _1_3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); textBox2.PasswordChar = '*';//密码以星号显示 } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { textBox1.Text = "";//清空文本框内容,下同 textBox2.Text = ""; } private void button1_Click(object sender, EventArgs e) { String st1 = textBox1.Text.Trim();//获取文本框内容 String st2 = textBox2.Text.Trim(); if(st1=="1808080112"&&st2=="123456") { MessageBox.Show("登陆成功!"); } if (st1!="1808080112"&&st2=="123456") { MessageBox.Show("用户名错误!"); textBox1.Text = ""; } if(st1=="1808080112"&&st2!="123456") { MessageBox.Show("密码错误!"); textBox2.Text = ""; } if(st1!="1808080112"&&st2!="123456") { MessageBox.Show("用户名、密码错误!"); textBox1.Text = ""; textBox2.Text = ""; } } } }