1. 程式人生 > >程式執行時智慧增減控制元件

程式執行時智慧增減控制元件

實現效果:

  

知識運用:

  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();
            }
        }