Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2006

Tip: Looking for answers? Try searching our database.

Trapping up/down arrow keys

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Kormann - 28 Mar 2006 05:08 GMT
I have a class that derives from a Windows forms datagrid and of instance of
this class is hosted within a Windows forms user control.  In the derived
class, I have overridden the ProcessDialogKey method and the
PreProcessMessage methods in hopes of trapping a press of the up and down
arrow keys.  However, these methods never execute.  It seems something else
is intercepting those key strokes, but I am at a loss.

What am I missing?

Thanks for you help.

Chris

Here is the code for the overridden methods:

protected override bool ProcessDialogKey(Keys keyData)
{
   if (keyData == Keys.Down || keyData == Keys.Up)
  {
       MessageBox.Show("ProcessDialogKey: " + keyData.ToString());
   }

  return base.ProcessDialogKey (keyData);
}

public override bool PreProcessMessage( ref Message msg )
{
  Keys keyCode = (Keys)(int)msg.WParam & Keys.KeyCode;
  if(msg.Msg == WM_KEYDOWN && (keyCode == Keys.Down || keyCode == Keys.Up) )
  {
      MessageBox.Show("PreProcessMessage: " + keyCode.ToString());
  }
  return base.PreProcessMessage(ref msg);
}
Vlado - 29 Mar 2006 12:22 GMT
>I have a class that derives from a Windows forms datagrid and of instance
>of
[quoted text clipped - 33 lines]
>   return base.PreProcessMessage(ref msg);
> }

First of all I think it's not good to call MessageBox.Show from there.
Instead you should put there e.g.

protected override bool ProcessDialogKey(Keys keyData)
{
   if (keyData == Keys.Down || keyData == Keys.Up)
  {
           this.SomeMethod();
           return true;
   }
   return base.ProcessDialogKey (keyData);
}

Also, you can try with overriding ProcessCmdKey

HTH

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.