码迷,mamicode.com
首页 > Windows程序 > 详细

C# 操作的时候接收用户输入密码进行确认

时间:2015-02-11 16:11:18      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

首先新建一个原始窗体,如下:

技术分享

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication11
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void tsSave_Click(object sender, EventArgs e)
        {
            if (rdb02.Checked)
            {
                FrmPwd f = new FrmPwd();
                f.FormClosed += new FormClosedEventHandler(f_FormClosed);  //事件通知
                f.ShowDialog();
            }
            else 
            {
                test();
            }            
        }

        void test()
        {
            MessageBox.Show("test");
        }       

        void f_FormClosed(object sender, FormClosedEventArgs e)
        {

            if ((sender as FrmPwd).isPASS)//isPASS 为接收密码输入的那个窗体里面的定义的全局变量,sender 为触发这个事件的参数
            {
                test();
            }
            else 
            {
                MessageBox.Show("密码错误");
            }
        }
    }
}

 

密码接收的窗体:

技术分享

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication11
{
    public partial class FrmPwd : Form
    {
        public bool isPASS = false; //如果密码正确,则赋值为true,默认为false

        public FrmPwd()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strPwd = this.textBox1.Text.Trim();
            if (strPwd == "12345")
            {                
                isPASS = true;               

            }
            this.Hide();
            this.Close();
        }
    }
}

 

需要校验密码的情况如下:

技术分享

 

技术分享

技术分享

技术分享

 

不需要校验密码的情况如下,直接执行对应的函数:

技术分享

 

C# 操作的时候接收用户输入密码进行确认

标签:

原文地址:http://www.cnblogs.com/allen0118/p/4286338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!