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

📄 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_5
{
    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 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 txtAddress_Enter(object sender, EventArgs e)
        {
            txtHelp.Text = "请输入您的地址!";
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string user = string.Empty;
            user = "姓名:" + txtName.Text + "\n";
            user = user + "密码:" + txtPassword.Text + "\n";
            user = user + "性别:" + (rdoMale.Checked ? "男" : "女") + "\n";
            user = user + "爱好:" + (chkMovie.Checked ? "电影 " : "") + (chkMusic.Checked ? "音乐 " : "") + (chkSport.Checked ? "体育 " : "") + "\n";
            DialogResult result = MessageBox.Show(user, "信息确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
            if (result == DialogResult.OK)
            {
                txtName.Clear();
                txtPassword.Clear();
                txtAgain.Clear();
                txtAddress.Clear();
                txtName.Focus();
            }
        }

        private void btnCancel_MouseEnter(object sender, EventArgs e)
        {
            txtName.CausesValidation = false;
            txtPassword.CausesValidation = false;
            txtAgain.CausesValidation = false;
        }

        private void btnCancel_MouseLeave(object sender, EventArgs e)
        {
            txtName.CausesValidation = true;
            txtPassword.CausesValidation = true;
            txtAgain.CausesValidation = true;
        }
    }
}

⌨️ 快捷键说明

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