backspace
-
When I will press the backspace it shouldnt delete at a paricular position.How to do it
-
When I will press the backspace it shouldnt delete at a paricular position.How to do it
Hello There are several approaches. This is the one I use:
bool ToChange = true;
string OldText = "";private void TextBox_KeyDownHandler(object sender, KeyDownArgs e)
{
If(e.KeyChar == "\b")
{
OldText = TextBox.Text;
ToChange = false;
}
else
ToChange = true;
}private void TextBox_TextChanged((object sender, KeyDownArgs e)
{
If(!ToChange)
{
TextBox.Text = OldText;
TextBox.SelectionStart = TextBox.TextLength;
}
}You see. The text hasn't changed when the keydown event was fired. So if we don't want to accept thechanges we store the original text in a string. Once the text has changed, the TextChanged event will be fired. It will check to see if we want to accept the changes. If not, revert to the old text. If anyone got a better approach, please post.:) Regards:rose:
-
When I will press the backspace it shouldnt delete at a paricular position.How to do it
Hi, You can also set the KeyChar = 0 in the KeyPress event ! I think you will have to cast 0 in to char for such assignment. Try it ! Hope it works !
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
-
When I will press the backspace it shouldnt delete at a paricular position.How to do it