SendKeys in C#
-
I want in my RichTextBox this action to do: Backspace key takes the same action like left arrow key. Speaking generally I don`t want to delete characters by backspace key inside the textBox field unless it is the last character. This code works in TextBox (do the action which I want) but unfortunatelly doesn`t work in RichTextBox.
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { char c = e.KeyChar; int start = textBox1.SelectionStart; int lenght = textBox1.Text.Length; if(c == (short)Keys.Back && start!=lenght) { e.Handled = true; SendKeys.Send("{LEFT}"); return; } }
Can anyone help me? -
I want in my RichTextBox this action to do: Backspace key takes the same action like left arrow key. Speaking generally I don`t want to delete characters by backspace key inside the textBox field unless it is the last character. This code works in TextBox (do the action which I want) but unfortunatelly doesn`t work in RichTextBox.
private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { char c = e.KeyChar; int start = textBox1.SelectionStart; int lenght = textBox1.Text.Length; if(c == (short)Keys.Back && start!=lenght) { e.Handled = true; SendKeys.Send("{LEFT}"); return; } }
Can anyone help me?Describe "how it is not working". Do you get a error or what? And aI think making this kind of behaviour is bad. There are standards and I hope you have a really god reason for doing this... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
-
Describe "how it is not working". Do you get a error or what? And aI think making this kind of behaviour is bad. There are standards and I hope you have a really god reason for doing this... Q:What does the derived class in C# tell to it's parent? A:All your base are belong to us!
You asked me why it doesn`t work. It takes two action in the same time. First it deletes charakters (so backspace key works like should work), second it moves cursor to left like I want. In textBox works only second action which exactly I want. In richTextBox work both of them.
e.Handled = true;
code should make a backspace key action not allowed. Why is that? I need this action in my richTextBox to validate text which I enter to this.