I just want to clear the digit when i press the backspace button
please help me find the code......
How to clear one digit in text box when ic lick backspace buton
Started by shyamenk, Feb 16 2011 02:13 AM
1 reply to this topic
#1
Posted 16 February 2011 - 02:13 AM
|
|
|
#2
Posted 16 February 2011 - 04:44 AM
I'm not sure exactly what you are asking, but you might be able to formulate an answer in here...
so you have a textbox, its just called 'txtBox1'
So, this is implicating that you have this properly wired up. if you pasted these into your code, you could wireup the events using the event designer, by selecting the control, then hitting the 'lightning bolt' icon in the properties form.
finding the related events, and selecting the methods in the drop down that match.
Anyways, the reason I think I'm missing the point, is that this somewhat mimics the natural behavior, except this shouldn't respond to holding down the backspace key, it will result in the removing of one character when the backspace key is let go...
anyways, a disussion starter, for sure.. =)
so you have a textbox, its just called 'txtBox1'
private void textBox1_KeyUp(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Back) {
if (((TextBox)sender).Text.Length == 0) return;
((TextBox)sender).Text = ((TextBox)sender).Text.Substring(0, ((TextBox)sender).Text.Length - 1);
((TextBox)sender).Select(((TextBox)sender).Text.Length,0);
}
return;
}
private void textBox1_KeyDown(object sender, KeyEventArgs e) {
if (e.KeyCode == Keys.Back) {
e.Handled = true;
}
return;
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) {
if (e.KeyChar == '\b') {
e.Handled = true;
}
return;
}
So, this is implicating that you have this properly wired up. if you pasted these into your code, you could wireup the events using the event designer, by selecting the control, then hitting the 'lightning bolt' icon in the properties form.
finding the related events, and selecting the methods in the drop down that match.
Anyways, the reason I think I'm missing the point, is that this somewhat mimics the natural behavior, except this shouldn't respond to holding down the backspace key, it will result in the removing of one character when the backspace key is let go...
anyways, a disussion starter, for sure.. =)
Edited by sam_coder, 16 February 2011 - 04:49 AM.
bug-if backspace was pressed with empty text box, end of world resulted
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









