欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#如何實(shí)現(xiàn)用戶名與密碼登錄

 更新時間:2023年07月12日 11:52:34   作者:不想學(xué)習(xí)只想玩  
這篇文章主要介紹了C#如何實(shí)現(xiàn)用戶名與密碼登錄問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

C#實(shí)現(xiàn)用戶名與密碼登錄

編寫一個C#窗體應(yīng)用程序,能夠輸入用戶名、密碼,并進(jìn)行登錄、取消等操作。

登錄界面設(shè)計

在這里插入圖片描述

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 = "";//清空文本框內(nèi)容,下同
            textBox2.Text = "";
        }
        private void button1_Click(object sender, EventArgs e)
        {
            String st1 = textBox1.Text.Trim();//獲取文本框內(nèi)容
            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.用戶名密碼均錯誤

在這里插入圖片描述

總結(jié)

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論