⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 C#2.0宝典源码,C#经典书籍,很多例子
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Example17_3
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void txtPassword_Validating(object sender, CancelEventArgs e)
        {
            if (txtPassword.Text.Trim() == string.Empty)
            {
                MessageBox.Show("密码为空,请重新输入!");
                txtPassword.Focus();
            }
        }

        private void txtName_Validating(object sender, CancelEventArgs e)
        {
            if (txtName.Text.Trim() == string.Empty)
            {
                MessageBox.Show("用户名为空,请重新输入!");
                txtName.Focus();
            }
        }

        private void txtAgain_Validating(object sender, CancelEventArgs e)
        {
            //验证第二次输入的密码是否为空
            //如不为空是否与第一次输入的密码相同
            //如不相同则清空,重新输入
            if (txtAgain.Text.Trim() == string.Empty)
            {
                MessageBox.Show("密码为空,请重新输入!");
                txtAgain.Focus();
            }
            else if (txtAgain.Text.Trim() != txtPassword.Text.Trim())
            {
                MessageBox.Show("密码输入有误,请重新输入!");
                txtPassword.Clear();
                txtAgain.Clear();
                txtPassword.Focus();
            }
        }

        private void txtGender_Validating(object sender, CancelEventArgs e)
        {
            //判断txtGender中输入的内容是否为“男”或“女”
            if ((txtGender.Text.Trim() != "男") && (txtGender.Text.Trim() != "女"))
            {
                MessageBox.Show("性别输入不正确,请重新输入!");
                txtGender.SelectAll();
                txtGender.Focus();
            }
        }

        private void txtName_Enter(object sender, EventArgs e)
        {
            txtHelp.Text = "请输入您的姓名!";
        }

        private void txtPassword_Enter(object sender, EventArgs e)
        {
            txtHelp.Text = "请输入您的密码!";
        }

        private void txtAgain_Enter(object sender, EventArgs e)
        {
            txtHelp.Text = "请再次输入您的密码!";
        }

        private void txtGender_Enter(object sender, EventArgs e)
        {
            txtHelp.Text = "请输入您的性别!";
        }

        private void txtAddress_Enter(object sender, EventArgs e)
        {
            txtHelp.Text = "请输入您的地址!";
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -