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

x
?
Solved

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

Posted on 2005-03-18
6
Medium Priority
?
321 Views
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!
0
Comment
Question by:mromeo
6 Comments
 
LVL 13

Accepted Solution

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

private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
      MessageBox.Show(e.KeyCode.ToString());
}

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

Author Comment

by:mromeo
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);
0
 
LVL 3

Expert Comment

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

Nick
0
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!

 
LVL 2

Expert Comment

by:klingzor
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");
}

0
 
LVL 13

Expert Comment

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

Author Comment

by:mromeo
ID: 13591015
I got it to work. Thanks.
0

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