在文本框的特定位置用*号替换

来源:互联网 发布:jq 数组删除元素方法 编辑:程序博客网 时间:2024/04/29 22:22

效果:



代码:

private void textBox1_TextChanged(object sender, EventArgs e)        {            string content = this.textBox1.Text;            int length = content.Length;            if(length>=5 && length<=7)            {                string temp = "";                if(length == 5)                {                    temp = content.Replace(content.Substring(4, 1), "*");                    }else if(length == 6)                {                    temp = content.Replace(content.Substring(5, 1), "*");                    }else if(length == 7)                {                    temp = content.Replace(content.Substring(6, 1), "*");                    }                this.textBox1.Text = temp;                textBox1.SelectionStart = textBox1.TextLength;//设置文本框选定的文本起点            }        }


原创粉丝点击