RichTextBox and SendKeys action
-
Does anyone of you can tell why the following code:
private void HandleKeyPress(object sender, KeyPressEventArgs e) { char c = e.KeyChar; if(c == (short)Keys.Back) { e.Handled = true; SendKeys.Send("{LEFT}"); return; } }
works in common textBox but it doesn`t work in richTextBox? In textBox linee.Handled = true;
stops the backspace key action and only action after pressing bakcspace key is move the cursor to left (SendKeys.Send("{LEFT}");
). In richTextBox it`s taken double action.e.Handled = true;
code doesn`t block backspace key action so: 1) first it deletes character (backspace key do it - it isn`t block) 2) second it moves the cursor to left (likeSendKeys.Send("{LEFT}");
code do) Can anyone figure out what`s wrong with it? -
Does anyone of you can tell why the following code:
private void HandleKeyPress(object sender, KeyPressEventArgs e) { char c = e.KeyChar; if(c == (short)Keys.Back) { e.Handled = true; SendKeys.Send("{LEFT}"); return; } }
works in common textBox but it doesn`t work in richTextBox? In textBox linee.Handled = true;
stops the backspace key action and only action after pressing bakcspace key is move the cursor to left (SendKeys.Send("{LEFT}");
). In richTextBox it`s taken double action.e.Handled = true;
code doesn`t block backspace key action so: 1) first it deletes character (backspace key do it - it isn`t block) 2) second it moves the cursor to left (likeSendKeys.Send("{LEFT}");
code do) Can anyone figure out what`s wrong with it?Try this private void richTextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.Equals(Keys.Back)) { e.SuppressKeyPress = true; SendKeys.Send("{LEFT}"); return; } } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.Equals(Keys.Back)) { e.SuppressKeyPress = true; SendKeys.Send("{LEFT}"); return; } }
-
Try this private void richTextBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.Equals(Keys.Back)) { e.SuppressKeyPress = true; SendKeys.Send("{LEFT}"); return; } } private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode.Equals(Keys.Back)) { e.SuppressKeyPress = true; SendKeys.Send("{LEFT}"); return; } }