By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,890 Members | 1,286 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,890 IT Pros & Developers. It's quick & easy.

ProcessCmdKey question?

P: n/a
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(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if(msg.WParam.ToInt32() == (int) Keys.Enter)
{
SendKeys.Send("{Tab}");
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
Nov 11 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 11 Nov 2008 15:12:19 -0800, Trooper <tr*@nema.emailwrote:
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
Nov 11 '08 #2

P: n/a
Peter Duniho wrote:
On Tue, 11 Nov 2008 15:12:19 -0800, Trooper <tr*@nema.emailwrote:
Thnx a lot. I get it all.
Nov 12 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.