程序运行时智能增减控件

Posted on 2018-12-30 20:37  努力成长静待花开  阅读(192)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  Button控件的Visible属性

  Form窗体的Show方法和Hide方法

实现代码:

        Frm frm = new Frm();
        private void button1_Click(object sender, EventArgs e)
        {
            if (txt_user.Text == "" || txt_pwd.Text == "")
                return;
            else if (txt_user.Text == "admin" && txt_pwd.Text == "admin")
            {
                frm.Text += "   "+"登陆用户:"+txt_user.Text;
                frm.Show();
                this.Hide();
            }
            else if (txt_user.Text == "user" && txt_pwd.Text == "user")
            {
                frm.Text += "   " + "登陆用户:" + txt_user.Text;
                frm.Show();
                frm.button3.Visible = false;
                frm.button4.Visible = false;
                this.Hide();
            }
            else 
            {
                MessageBox.Show("用户名或密码输有误");
                txt_user.Text = "";
                txt_pwd.Text = "";
                txt_user.Focus();
            }
        }