Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
I am creating a calculator using c#, I just want that my backspace should work on textBoxes.
I have a button that should performs functionality of backspace.
Posted
Updated 27-Mar-11 18:30pm
v2
Comments
[no name] 28-Mar-11 0:18am    
What do you mean backsapce does not work, would you please clear this
[no name] 28-Mar-11 0:31am    
Thats good its easy now..

Backspace character does work on all text boxes unless you handled some event to prevent that.
You need to show a fragment of you code to get further help.

Please see my Answer to your other Question (How to save 2 values in a variable[^]) and thing thoroughly: you need to select much easier coding tasks as you only start programming and still have to learn the very basic idea.

[EDIT] See my separate Answer done after clarification by OP.

—SA
 
Share this answer
 
v2
Comments
Abhinav S 28-Mar-11 0:35am    
Good answer. My 5.
Sergey Alexandrovich Kryukov 28-Mar-11 0:42am    
Thank you, Abhinav.
--SA
I hope you are handling backspace using the System.Windows.Forms.Keys.Back keycode.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 28-Mar-11 0:41am    
A useful hint, my 5. (I fixed the ID to make it compile, would you mind?).
--SA
Abhinav S 28-Mar-11 0:52am    
Oh no not at all. Thanks for the 5.
Sergey Alexandrovich Kryukov 28-Mar-11 0:47am    
She accepted the completely incorrect Answer. This is useless...
--SA
m@dhu 28-Mar-11 0:50am    
If you could look at her profile and the comments you will know it why?
Sergey Alexandrovich Kryukov 28-Mar-11 0:56am    
I did. She and Brijesh work together to mess up most simple things. Being not experienced is one thing, moving in wrong direction is something else... And not listening... Useless, I say...
--SA
Answering a follow-up Question:

This is one of the ways to emulate backspace:

C#
myButton.Click += (sender, eventArgs) => {
    myTextBox.Focus();
    Application.DoEvents();
    SendKeys.Send("{BACKSPACE}");
};


Warning! Avoid using Application.DoEvents for other cases; one common mistake is doing it periodically as a dirty substitute of threading.

A variant without SendKeys:

C#
myButton.Click += (sender, eventArgs) => {
int currentPosition = myTextBox.SelectionStart;
if (currentPosition > 0)
    myTextBox.Text = myTextBox.Text.Remove(currentPosition - 1, 1);
};


—SA
 
Share this answer
 
v2
Comments
[no name] 28-Mar-11 2:05am    
Really Good Sample.
Have My 5
Sergey Alexandrovich Kryukov 28-Mar-11 2:14am    
Thank you very much.
Importantly, it provides required functionality.
--SA
Bhavna v 29-Mar-11 1:18am    
Thank for solution.
Sergey Alexandrovich Kryukov 29-Mar-11 1:20am    
You are welcome.
--SA

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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