1. 程式人生 > >如何讓文字框顯示提示資訊

如何讓文字框顯示提示資訊

QQ上輸入賬號密碼的時候會有一個提示資訊,這個是如何實現的呢?

正文

        //使用者名稱自動提示
        private void txtUserID_Enter(object sender, EventArgs e)
        {
            txtUserID.Focus();
            txtUserID.Text = "請輸入使用者名稱";

            txtUserID.ForeColor = Color.LightGray;
        }

        private void txtUserID_Leave(object sender, EventArgs e)
        {
            if (txtUserID.Text == "")
            {
                txtUserID.Text = "請輸入使用者名稱";
                txtUserID.ForeColor = Color.LightGray;
            }

        }
        //點選使用者文字框,內容清空
        private void txtUserID_MouseClick(object sender, MouseEventArgs e)
        {
            txtUserID.Text = "";
        }

        private void txtPassWord_MouseClick(object sender, MouseEventArgs e)
        {
            txtPassWord.Text = "";
        }



        //密碼自動提示
        private void txtPassWord_Enter(object sender, EventArgs e)
        {
            txtPassWord.Text = "請輸入密碼";
            txtPassWord.ForeColor = Color.LightGray;
        }
        //離開自動回覆密碼提示
        private void txtPassWord_Leave(object sender, EventArgs e)
        {
            if (txtPassWord.Text == "")
            {
                txtPassWord.Text = "請輸入密碼";
                txtPassWord.ForeColor = Color.LightGray;
            }

        }
        //密碼框為*
        private void txtPassWord_TextChanged(object sender, EventArgs e)
        {
            if (txtPassWord.Text == "" && txtPassWord.Text != "請輸入密碼")
            {
                txtPassWord.PasswordChar = Convert.ToChar("*");
            }

        }
        

小結

這個功能邏輯有點繞,還需要再研究一下。