C# WinForm 的TextBox怎么编程去掉最后一个字符?

2025-02-24 04:56:22
推荐回答(3个)
回答1:

给你个基本原理的代码
void Button1Click(object sender, EventArgs e)
{
string strNew = this.textBox1.Text.Substring(0,this.textBox1.Text.Length-1);
this.textBox1.Text = strNew;
this.textBox1.SelectionStart = this.textBox1.Text.Length;
this.textBox1.Focus();
}
主要就是设置SelectionStart 这个属性和 让textbox获得焦点

回答2:

假设textbox 的 id 为 TextBox1

Main函数中写

string strTest=this.TextBox1.Text;
strTest=StrTest.substring(0,strTest.length-1);
this.TextBox1.Text=strTest;

this.TextBox1.focus();

回答3:

string strTest=StrTest.substring(0,strTest.length-1);
textBox1.Focus();

这样就行了·!