C#如何实现用户名与密码登录

Echo ·
更新时间:2024-09-20
· 1789 次阅读

目录

C#实现用户名与密码登录

登录界面设计

效果如下

1.用户名与密码均正确

2.用户名错误,密码正确

3.用户名正确,密码错误

4.用户名密码均错误

总结

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 = ""; } } } } 效果如下 1.用户名与密码均正确

2.用户名错误,密码正确

3.用户名正确,密码错误

4.用户名密码均错误

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持软件开发网。



C# 用户名

需要 登录 后方可回复, 如果你还没有账号请 注册新账号