在C#中逐个删除数字 [英] Delete Number One By One in C#

查看:83
本文介绍了在C#中逐个删除数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我创建了一个非常漂亮的GUI计算器,但我希望我的计算器用户逐个删除数字而不是清除所有内容从文本框中立刻。如何编写退格按钮的代码?我是否需要真正创建一个按钮,或者有一种方法可以将代码写入每个btn1,btn2等按钮,使用户能够逐个减少数字?



例如,我想输入123,我输入了132,我想删除32而不是清除所有数字,包括一个。



你的需要帮助..

解决方案

参考 - C#中的简单计算器 [ ^ ]

Quote:

  private   void  btnBackspace_Click( object  sender,EventArgs e)
{
// 退格
if (txtResult.Text!= string .Empty)
{
int txtlength = txtResult.Text.Length;
if (txtlength!= 1
{
txtResult。 Text = txtResult.Text.Remove(txtlength - 1 );
}
else
{
txtResult.Text = 0 的ToString();
}
}
}






请试试这个。



<前lang =cs> 私人 void button1_Click( object sender,EventArgs e)
{
textBox1.Focus();
Application.DoEvents();
SendKeys.Send( {BACKSPACE});
}


使用下面的代码



  string  s =   0; 
if (TextBox1.Text.Length > 1
{
s = TextBox1.Text;
s = s.Substring( 0 ,s.Length - 1 );
}
TextBox1.Text = s;


Hi,

I have created a calculator with a very nice GUI, but I want the users of my calculator to delete numbers one by one instead of clearing everything at once from the textbox. How do I write a code for the backspace button? Do I need to create a button really or there is a way to write the code to each btn1, btn2 etc buttons that will enable the user to reduce numbers one by one?

For example, I want to type 123 and by mistake, I typed 132 and I want to remove the 32 instead of clearing all the numbers including one.

your help is needed..

解决方案

Refer - Simple Calculator in C#[^]

Quote:

private void btnBackspace_Click(object sender, EventArgs e)
{
    //backspace
    if (txtResult.Text != string.Empty)
    {
        int txtlength=txtResult.Text.Length;
        if (txtlength != 1)
        {
            txtResult.Text = txtResult.Text.Remove(txtlength - 1);
        }
        else
        {
            txtResult.Text = 0.ToString();
        }        
    }
}


Hi,

Please try this.

private void button1_Click(object sender, EventArgs e)
        {
            textBox1.Focus();
            Application.DoEvents();
            SendKeys.Send("{BACKSPACE}");
        }


use below code

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


这篇关于在C#中逐个删除数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆