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 / October 2007

Tip: Looking for answers? Try searching our database.

KeyPress Not Firing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
HaySeed - 22 Oct 2007 07:45 GMT
I have a series of graphical User controls on the screen which which do not
posess any user input controls so no tab stops.  I need to have them respond
to key press events to move left or right (arrow keys) or Delete. My problem
is I can't get the KeyPress event to fire for any keys standard or non
standard.

I have set the Form's Keypress property to True but want to capture the
keypress inside the UserControls themselves.  I have Set the UserControl's
KeyPress Event as well as tried overriding the OnKeyDown, OnKeyPress, and
IsInputKey.

Still I am not triggering the KeyDown or KeyPress events.

Is there a trick to this???
Bob Powell [MVP] - 22 Oct 2007 16:13 GMT
Override the ProcessCmdKey method.

Signature

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

>I have a series of graphical User controls on the screen which which do not
> posess any user input controls so no tab stops.  I need to have them
[quoted text clipped - 12 lines]
>
> Is there a trick to this???
HaySeed - 22 Oct 2007 23:16 GMT
Thanks Bob - ProcessCmdKey does trap the event on the form but not at the
UserControl level.  Is there anyway to capture the event at the UserControl
or must the form be made "aware" of the various controls it holds and their
states?

> Override the ProcessCmdKey method.
>
[quoted text clipped - 14 lines]
> >
> > Is there a trick to this???
Bob Powell [MVP] - 23 Oct 2007 10:02 GMT
It's the responsibility of each window to trab events when it has the focus.
As your user controls get the focus, they will be given the opportunity to
deal with events such as key press and mouse move etc. If you've done
nothing to these controls to handle the events they will just be ignored.

If you have control over the source for these user controls you must build
in the abilities you need or perhaps handle the correct events on the
controls to trap them in the form.

Signature

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

> Thanks Bob - ProcessCmdKey does trap the event on the form but not at the
> UserControl level.  Is there anyway to capture the event at the
[quoted text clipped - 24 lines]
>> >
>> > Is there a trick to this???

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.