今天使用系统的修改密码时,发现window7的修改密码文本框里边的提示文本,自己没什么事也做了一个,
其它没有什么,只是在为passwordChar附上值的时候,就不行了,大给给想想办法。我知啊窗体的那控件的TextChanged写上以下在,是可以实现的
private void suggestiveTextBox1_TextChanged(object sender, EventArgs e)
        {
            if (suggestiveTextBox1.Text==suggestiveTextBox1.SuggestiveText)
            {
                suggestiveTextBox1.PasswordChar = new char();
            }
            else
            {
                suggestiveTextBox1.PasswordChar = '*';
            }
        }但我觉得这样不好,请大家帮忙想想怎么在设计控件时就实现这个功能,只要是不知道用户是否给passwordchar赋值没有???下边是全部代码using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;namespace SuggestiveTextBox
{
    [ToolboxBitmap(typeof(TextBox))]
    public partial class SuggestiveTextBox : TextBox
    {
        public SuggestiveTextBox()
        {
            InitializeComponent();
            this.Text = SuggestiveText;
            InputColor = Color.Black;
            SugestiveColor = Color.DimGray;            
            this.TextChanged += new EventHandler(SuggestiveTextBox_TextChanged);
            this.MouseLeave += new EventHandler(SuggestiveTextBox_MouseLeave);
            this.Click += new EventHandler(SuggestiveTextBox_Click);
            this.KeyDown += new KeyEventHandler(SuggestiveTextBox_KeyDown);
            this.Enter += new EventHandler(SuggestiveTextBox_Enter);
            
           // password = PasswordChar;
        }
        //private char password;
        //判断是否为用户的操作 如鼠标单击,或键盘按下
        private bool isUserInfo = false;
        /// <summary>
        /// 获取光标事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void SuggestiveTextBox_Enter(object sender, EventArgs e)
        {
            if (this.Text == "")//如果没有值则显示提示文本
            {
                this.Text = SuggestiveText;
                this.ForeColor = SugestiveColor;//前景色为提示文本颜色
                this.Select(0, 0);//不选中
            }
           
        }
        /// <summary>
        /// 按下键盘时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void SuggestiveTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.Text == SuggestiveText)//当为提示文本时 设置前景色为输入文本颜色 并清空
            {
                isUserInfo = true;//标记为自己输入
                this.ForeColor = InputColor;
                this.Text = "";            }
            else//只设前景色为输入文本
            {
                this.ForeColor = InputColor;
                isUserInfo = false;
            }
        }
        /// <summary>
        /// 鼠标单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void SuggestiveTextBox_Click(object sender, EventArgs e)
        {
            if (this.Text == SuggestiveText)//单击是清空文本
            {
                isUserInfo = true;
                this.Select(0, 0);
                this.Text = "";
            }
            else
            {
                isUserInfo = false;
            }
        }
        /// <summary>
        /// 鼠标离开时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void SuggestiveTextBox_MouseLeave(object sender, EventArgs e)
        {
            if (this.Text == "")//如果为空则显示提示文本
            {
                
                this.Text = SuggestiveText;
                this.ForeColor = SugestiveColor;
                this.Focus();
            }
        }
        
        /// <summary>
        /// 值改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void SuggestiveTextBox_TextChanged(object sender, EventArgs e)
        {
            if (this.Text == "" && isUserInfo == false)//当为空时并且有用户删除导致时
            {
                this.Text = SuggestiveText;//提示文本
                this.ForeColor = SugestiveColor;//提示文本颜色
            }
            if (this.Text ==SuggestiveText)//当为提示文本时
            {
                this.ForeColor = SugestiveColor;
                this.Select(0, 0);//设置不被选中
                //this.PasswordChar = new char();
            }
            else//为其它时 设置前景色为 输入文本颜色
            {
                this.ForeColor = InputColor;
               // this.PasswordChar = '*';
            }        
        }
        //属性        private string sugestiveText;
        [Description("提示文本")]
        public string SuggestiveText
        {
            get { return sugestiveText; }
            set { sugestiveText = value;
            this.Text = sugestiveText;
            }
        }        private Color sugestiveColor;
        [Description("提示文本颜色")]      
        public Color SugestiveColor
        {
            get { return sugestiveColor; }
            set { sugestiveColor = value; }
        }        private Color inputColor;
        [Description("输入文本颜色")]
        public Color InputColor
        {
            get { return inputColor; }
            set { inputColor = value; }
        }
        
    }
}