Re: How to handle Ctrl+Enter
From: Morten Wennevik (MortenWennevik_at_hotmail.com)
Date: 03/06/05
- Next message: Jon Skeet [C# MVP]: "Re: is this a bug of JIT?"
- Previous message: Jon Skeet [C# MVP]: "Re: Compiler error found... I was wrong, This is a logic error by design"
- In reply to: Coder: "How to handle Ctrl+Enter"
- Next in thread: Coder: "Re: How to handle Ctrl+Enter"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 06 Mar 2005 16:27:21 +0100
Hi Coder,
You can check for Ctrl inside the KeyPress event by using the static
properties Control.ModifierKeys
In theory you should be able to do
if(e.KeyChar == (char)13 && Control.ModifierKeys == Keys.Ctrl)
Except this doesn't work. Modifierkeys are translated to characters
inside the KeyPress event. When you hold ctrl while clicking Enter
(char)10 is sent instead of (char)13 and the Control click is suppressed,
so all you have to do to detect Ctrl+Enter is
if(e.KeyChar == (char)10)
The same goes for other combinations like
if(e.KeyChar == (char)97) // [A]
if(e.KeyChar == (char)1 ) // [CTRL]+[A]
To detect key combinations put something like this inside the KeyPress
event
MessageBox.Show(((int)e.KeyChar).ToString());
In the end, you might be better off using the KeyUp/KeyDown events as
Joshua said
-- Happy Coding! Morten Wennevik [C# MVP]
- Next message: Jon Skeet [C# MVP]: "Re: is this a bug of JIT?"
- Previous message: Jon Skeet [C# MVP]: "Re: Compiler error found... I was wrong, This is a logic error by design"
- In reply to: Coder: "How to handle Ctrl+Enter"
- Next in thread: Coder: "Re: How to handle Ctrl+Enter"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|