从C#中的文本框中删除最后一个字符

时间:2015-10-10 18:19:28

标签: c#

我想要一个按钮来删除文本框中的最后一个字符,比如Windows计算器中的左箭头按钮

private void button15_Click(object sender, EventArgs e)
{

}

3 个答案:

答案 0 :(得分:2)

这个怎么样?

private void button15_Click(object sender, EventArgs e)
{
    string sYourText = txtYourTextBox.Text;
    if (!String.IsNullOrEmpty(sYourText)){
       sYourText = sYourText.substring(0, sYourText.Length -1);
           txtYourTextBox.Text = sYourText;   
    }
}

答案 1 :(得分:1)

除非没有其他要求,否则这就是您所需要的

var text = "something"; //your TextBox.Text
if (text.Length > 0)
    text = text.Remove(text.Length - 1);

答案 2 :(得分:1)

private void button15_Click(object sender, EventArgs e)
{
    var text = txtSomething.Text;
    txtSomething.Text = text.Remove(text.Length - 1);
}