HeX
{ USER }
posts: 8
last: 11-Aug-2008
TITLE: Catch a key stroke before the actual control
DESCRIPTION: Catch a key stroke before the actual control
Submitted: 19-Sep-2007 12:56:32 ( 1yrs 15w 5d 20h ago ) Language: C# (*.cs)
Views: 273 Lines of Code: 28 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 0.00 / 5 }
Difficulty: Beginner
Bookmark
// KeyDown event of some control
private void SomeControl_KeyDown(object sender, KeyEventArgs e)
{
    // 1. Event is called directly after the key stroke
 
    // If the user hits Enter, we catch the
    // event and do our own things
    if (e.KeyCode == Keys.Enter)
    {
        // Suppress key stroke, so that
        // the control don't receives it
        e.SuppressKeyPress = true;
 
        // Perform something important...
    }
}
 
// KeyPress event of some control
private void SomeControl_KeyPress(object sender, KeyPressEventArgs e)
{
    // 2. Event is called during the key stroke
}
 
// KeyUp event of some control
private void SomeControl_KeyUp(object sender, KeyEventArgs e)
{
    // 3. Event is called after the key stroke  
}