Results 1 to 4 of 4

Thread: Form's KeyDown Event

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Hong Kong
    Posts
    83

    Form's KeyDown Event

    Form1_KeyDown can't be raised up after navigating DataGrid by KeyBoard's Up/Down Key.
    Any solution for this case?

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Add this:

    Code:
    // Add to the Form_Load() Event
    this.KeyPreview = true;

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Hong Kong
    Posts
    83
    Thx for replying, but it's not the solution.

    The form's KeyPreview property has been set to be True already.
    The Form's KeyDown Event can be raised up.

    ???But after navigating the DataGrid by UP/DOWN Key,
    the Form's KeyDown Event can't be raised up.???

    If I click on the DataGrid, the Form's KeyDown Event can be raised up again.

    How can I solve this problem?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Location
    Hong Kong
    Posts
    83
    public class Form1 : System.Windows.Forms.Form, IMessageFilter
    {
    const int WM_KEYDOWN = 0x100;
    public bool PreFilterMessage(ref Message m)
    {
    Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
    if(m.Msg == WM_KEYDOWN)
    {
    ...
    return true;
    }
    return false;
    }
    ....
    private void Form1_Load(object sender, System.EventArgs e)
    {
    Application.AddMessageFilter(this);
    }
    }

    These codes run so good to catch the KeyDown action!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width