Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How do you detect when the CTRL is pressed in the RichTextBox

Posted on 2005-03-18
Medium Priority
Last Modified: 2010-08-05

I have a RichTextBox in my C# application, and I want to do something similar to what the IDE does when it recognizes a class name and pops up a list box of possible properties/methods/events for you to choose from.  I want to be able to detect when the user presses the CTRL (or any other modifier) key in a RichTextBox and pop up a list of items for them to choose from.  KeyPress and KeyDown do not get called  when a modifier is pressed.  ModifiedChanged doesn't work either.  How can I detect when the CTRL is pressed in this control?  Also, if you have any advice on popping up a list box, I'd appreciate hearing it.  Thanks!
Question by:mromeo
LVL 13

Accepted Solution

dungla earned 600 total points
ID: 13575402
mromeo, Keydown working greate

private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)

will return ControlKey when press Ctrl, Menu when press Alt and so on

Author Comment

ID: 13575524

This is not working for me.  How did you add the event to the rich text box.  I did, the following:

rich.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.rich_KeyDown);

Expert Comment

ID: 13576526
it needs to be "this.richTextBox1_KeyDown".  You've just got "this.rich_KeyDown"...

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 13587939
Also, be sure to wire it to the correct event ;)


this.richTextBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.richTextBox1_KeyDown);


private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
      if (e.Modifiers == Keys.Control)
            MessageBox.Show(this, "CTRL was pressed");

LVL 13

Expert Comment

ID: 13587997
mromeo, very simple, select rich textbox on desing screen, open property bag, double click on KeyDown event. That's all.

Author Comment

ID: 13591015
I got it to work. Thanks.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question