如何从TextBox中删除最后一个字符?

Zig*_*gnd 2 c#

我正在尝试写一份MS Windows计算器 - 只是为了练习我在我正在做的课程中获得的知识 - 而且我在编写Backspace密钥方面遇到了问题,但我不知道如何删除TxtResult.Text(文本框)上的最后一个字符.那么,有人可以教我怎么做吗?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ZigndSuperCalc
{
    public partial class FrmZigndSC : Form
    {
        Int64 aux, result;
        Int16 cont = 0;
        bool sucess;
        public FrmZigndSC()
        {
            InitializeComponent();
        }

        private void BtnSoma_Click(object sender, EventArgs e)
        {
            sucess = Int64.TryParse(TxtInput.Text, out aux);
            result += aux;
            TxtInput.Text = Convert.ToString(result);
            TxtInput.Focus();
        }

        private void BtnCE_Click(object sender, EventArgs e)
        {
            TxtInput.Text = "0";
        }

        private void BtnC_Click(object sender, EventArgs e)
        {
            result = 0;
            TxtInput.Text = "0";
        }

        private void BtnBackspace_Click(object sender, EventArgs e)
        {
            // write here a method to delete the last character from 
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

rei*_*ein 12

如果我们正在模仿calc.exe,那么它可能是这样的:

string s = TxtResult.Text;

if (s.Length > 1) {
    s = s.Substring(0, s.Length - 1);
} else {
    s = "0";
}

TxtResult.Text = s;
Run Code Online (Sandbox Code Playgroud)

编辑:根据要求,Substring我在这里使用的方法提取字符串的一部分,并将其分配给Text文本框的属性.请参阅:http://msdn.microsoft.com/en-us/library/aka44szs.aspx