I'm using a RichTextBox (.NET WinForms 3.5) and would like to override some of the standard ShortCut keys....
For example, I don't want Ctrl+I to make the text italic via the RichText method, but to instead run my own method for processing the text.
Any ideas?
Ctrl+I isn't one of the default shortcuts affected by the ShortcutsEnabled property.
The following code intercepts the Ctrl+I in the KeyDown event so you can do anything you want inside the if block, just make sure to suppress the key press like I've shown.
private void YourRichTextBox_KeyDown(object sender, KeyEventArgs e)
{
if ((Control.ModifierKeys & Keys.Control) == Keys.Control && e.KeyCode == Keys.I)
{
// do whatever you want to do here...
e.SuppressKeyPress = true;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With