目录
- 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.用户名密码均错误
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)