运行时,先显示登陆窗口,如果通过验证,则关闭登陆窗口,启动操作窗口,如果连续四次登陆不成功,则程序自动关闭

解决方案 »

  1.   

    我是说我自己混日子——盼望lz给分,并不是针对lz而言的。
      

  2.   

    private void button2_Click(object sender, EventArgs e)//click登陆botton时进行反序列化和用户名的辨别
            {
               
                try
                {
                    BinaryFormatter tin = new BinaryFormatter();
                    Stream cstream = new FileStream("Data/oo.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
                    CodeNumber ctxt = (CodeNumber)tin.Deserialize(cstream);
                    cstream.Close();
                 int i=0;
                 while(i<=4){
                    if (this.textBox1.Text != ctxt.nameback())
                    {
                        MessageBox.Show("错误的用户名!请重试", "登录");
                        this.textBox1.Focus();//控件的输入点
                        this.textBox1.Text = "";
                        this.textBox2.Text = "";
                    }
                    else if (this.textBox2.Text != ctxt.numberback())
                    {
                        MessageBox.Show("错误密码!请重试", "登录");
                        this.textBox2.Focus();
                        this.textBox2.Text = "";
                    }
                    else //用户名和密码正确,关闭模式对话框
                    {
                        this.DialogResult = DialogResult.OK;
                    }
                     i++;
                   }//while结束
                }//try结束
                catch (Exception cs)
                {
                    MessageBox.Show("****文件对话框出现小小的毛病,请与软件设计人员联系****" + cs);
                }
                
            }这里是我做的 登陆窗体代码 用到序列化  你也可以不用序列化 用数据库 运行 登陆窗体 代码为
                        Form2 frmLogin = new Form2();
                        frmLogin.ShowDialog(this); //form1作为模式对话框的拥有者