C#中的退格函数 [英] Backspace function in C#

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

问题描述

伙计们,我想为我的科学计算器项目编写一个退格函数,我编写了类似这样的内容



hi guys i want to program a backspace function for my Scientific Calculator Project i coded something like this

private void button48_Click(object sender, EventArgs e)

{

textBox_Result.Text = textBox_Result.Text.Remove(textBox_Result.Text.Len gth - 1);

if (isOperationPerformed == true)

{

textBox_Result.Text = textBox_Result.Text;

}

else if (textBox_Result.Text == "")

{

textBox_Result.Text = "0";

}





i希望此代码仅在未执行操作但操作执行为真时才起作用不应该工作,但它似乎不起作用



我尝试过:



尝试if else类型函数但不起作用:(



i want this code to work only when operation is not performed but if operation performed true then it should not work but it not seems to work

What I have tried:

Tried if else type functions but that doesn't worked :(

推荐答案

private void button48_Click(object sender, EventArgs e)
{
   if (isOperationPerformed == true)
   {
    // do nothing
   }
   else if (textBox_Result.Text.Length > 0)
   {
     textBox_Result.Text = textBox_Result.Text.Remove(textBox_Result.Text.Length - 1);   
   }
 
}


使用 SendKeys.Send方法(字符串)(System.Windows.Forms) [ ^ ]



use SendKeys.Send Method (String) (System.Windows.Forms)[^]

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


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

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