Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture Ctrl-Z keystroke in a RichTextBox

I need to capture when the user presses CTRL-Z (press CTRL and Z at the same time) in a RichTextBox control.

I've turned off the ShortCutsEnabled property. I've tried every combination I can think of using KeyCode and KeyData with the KeyDown and KeyPress events.

I can capture EITHER a CTRL OR a Z, but never both together. Is RichTextBox capturing this keystroke before I can see it, even if shortcuts are disabled?

Does anyone have a solution that works for this?

like image 953
user3539628 Avatar asked Apr 16 '14 04:04

user3539628


People also ask

How to create a RichTextBox control at run-time?

Creating a RichTextBox control at run-time is merely a work of creating an instance of RichTextBox class, setting it's properties and adding the RichTextBox object to the Form's Controls collection. The first step to create a dynamic RichTextBox is to create an instance of the RichTextBox class.

How do I disable shortcuts in a RichTextBox?

The following code snippet disables shortcuts in a RichTextBox. The simplest way of reading a RichTextBox control contents is using the Text property. Note however that the Text property has no formatting; it has only text. See the Rtf property for the text including the formatting.

How do I drag and drop text from RichTextBox?

RichTextBox control supports drag and drop operations that allow us to drag and drop text, picture, and other data. EnableAutoDragDrop property enables drag-and-drop operations on text, pictures, and other data. RightMargin property represents the size of a single line of text within a RichTextBox control.

How do I read a RichTextBox?

The simplest way of reading a RichTextBox control contents is using the Text property. Note however that the Text property has no formatting; it has only text. See the Rtf property for the text including the formatting.


1 Answers

you could simply use CTRL-Z

 textBox1.KeyDown += new KeyEventHandler(textBox1_KeyDown);

void textBox1_KeyDown(object sender, KeyEventArgs e)
    {
         if(e.KeyCode == Keys.Z && (e.Control)) {
             MessageBox.Show("Ctrl + Z Pressed!");
         }
    }
like image 93
Umar Abbas Avatar answered Oct 11 '22 16:10

Umar Abbas