Click here to Skip to main content
15,077,641 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 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 :(
Posted
Updated 4-Oct-17 1:49am

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);   
   }
 
}
   
Comments
Vicky Malhotra 4-Oct-17 8:10am
   
Hey thanks man it works only when i use isOperationPerforemed == false but it also works when operation is not performed i want to remove the text if operation is not performed.
Here is my source code~ https://pastebin.com/USeeZXuF
CPallini 4-Oct-17 8:52am
   
And how do you tell that 'operation is not performed'?
Vicky Malhotra 4-Oct-17 8:56am
   
you can see my source code: https://pastebin.com/USeeZXuF
i defined bool isOperationPerformed = false;
=|
CPallini 4-Oct-17 9:08am
   
Probably I don't get you. Do you mean that nothing happens (no character removal) when (isOperationPerformed == false) ?
Vicky Malhotra 4-Oct-17 9:17am
   
No :( it not removes anything when i define false and when i define true it removes even when operation is performed!
CPallini 4-Oct-17 9:34am
   
You have two variables:
isOperationPerformed (boolean) and OperationPerformed (string).
What should do the Backspace handler in the following cases:
isOperationPerofmed OperationPerformd
1 false (empty string)
2 false (not empty string)
3 true (empty string)
4 true (not empty string)
?
Vicky Malhotra 4-Oct-17 9:36am
   
Oh so i need to define other variable for that? Actually i'm noob :(
CPallini 4-Oct-17 9:40am
   
Actually you don't have to. But you did, in your code.
Vicky Malhotra 4-Oct-17 9:44am
   
But it's not working out, what's the problem? :/
CPallini 4-Oct-17 9:49am
   
Really I don't know. I am not able to understand what you are trying to do with such a handler.
use SendKeys.Send Method (String) (System.Windows.Forms)[^]

private void button1_Click(object sender, EventArgs e)
       {
           textBox1.Focus();
           SendKeys.Send("{BACKSPACE}");
       }
   
Comments
Vicky Malhotra 4-Oct-17 8:12am
   
Thanks but it's not that what i want :|
Vicky Malhotra 4-Oct-17 8:39am
   
Here is my source code~ https://pastebin.com/USeeZXuF
If you can figure this then pls do thanks
Karthik_Mahalingam 4-Oct-17 23:39pm
   
what you are trying to achieve

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900