?
Solved

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

Posted on 2005-03-18
6
Medium Priority
?
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

764 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