在文本框的特定位置用*号替换 分类: .NET 2012-04-28 11:13 493人阅读 评论(1) 收藏
效果:

代码:
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;//设置文本框选定的文本起点
}
}版权声明:本文为博主原创文章,未经博主允许不得转载。
浙公网安备 33010602011771号