效果:
代码:
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;//设置文本框选定的文本起点
}
}