ProcessCmdKey question?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Trooper

    #1

    ProcessCmdKey question?

    Hi!

    I need help with calling ProcessCmdKey. I'm little bit confused
    how to use this method from my app. How to call it, from where?
    Can somebody explain to me?

    Thnx.

    This is the source:

    public class MyDataGrid : DataGrid
    {
    protected override bool ProcessCmdKey(r ef System.Windows. Forms.Message msg, System.Windows. Forms.Keys keyData)
    {
    if(msg.WParam.T oInt32() == (int) Keys.Enter)
    {
    SendKeys.Send(" {Tab}");
    return true;
    }
    return base.ProcessCmd Key(ref msg, keyData);
    }
    }
  • Peter Duniho

    #2
    Re: ProcessCmdKey question?

    On Tue, 11 Nov 2008 15:12:19 -0800, Trooper <trp@nema.email wrote:
    Hi!
    >
    I need help with calling ProcessCmdKey. I'm little bit confused
    how to use this method from my app. How to call it, from where?
    Can somebody explain to me?
    As the code you posted (you write "this is the source"...the "source" from
    where? why is it relevant to your question?) shows, you don't call the
    method, you override it. The framework calls it during processing of
    window messages, providing the Control instance with an opportunity to
    intercept specific messages for special processing.

    For example, in your code example, the method is trapping the Enter key
    and converting it to a Tab key (presumably to cause the Enter key to move
    focus to the next control, just as the Tab key does).

    I'm not sure the example you showed is actually the best demonstration of
    why one would use it; after all, there are less-invasive ways to catch the
    Enter key and use it to move focus. But it does show the basic idea: it's
    a way of processing or transforming the raw input at an early stage.

    As the MSDN docs state, it would be very unusual for someone to need to
    write code that overrides this method. But if you have the need, it's
    there for just that purpose.

    Pete

    Comment

    • Trooper

      #3
      Re: ProcessCmdKey question?

      Peter Duniho wrote:
      On Tue, 11 Nov 2008 15:12:19 -0800, Trooper <trp@nema.email wrote:
      >
      Thnx a lot. I get it all.

      Comment

      Working...