C# 编个退位键 怎么写代码呢

删除textbox中最后一位。代码怎么写呢!
2025-03-20 17:25:32
推荐回答(3个)
回答1:

private void button1_Click(object sender, EventArgs e)
{
this.textBox1.Focus();
SendKeys.Send("{PGDN}");
SendKeys.Send("+{HOME}");
SendKeys.Send("+{DEL}");
}
删除最后一行,纯正退位键实现

回答2:

这个需要退位键吗,你可以借助API sendkey,好像是的,或者最简单的方法:
textbox.text=textbox.text.substring(0,textbox.text.length-1-2);

回答3:

个字符?

string test = textbox.Text;
if (!string.IsNullOrEmpty(test))
{
test = test.Substring(0, test.Length - 1);
}
textbox.Text = test;