Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Keypress Event Handler linked to the Form itself.

Posted on 2007-07-26
2
Medium Priority
?
470 Views
Last Modified: 2011-09-20
Is there a way to give the form itself a KeyPressEventArgs?

I am writing a program for individuals with learning disabilities. Part of the design philosphy of the form is to have as little as possible that is clickable. Therefore they can't click into an area that they shouldn't. This is needed since their coordination with a mouse is very poor. That is the purpose of the application.

So, having a menu & minimize and maximize buttons are kind of a bad thing. In my application, the only things clickable is the "close program" X button in the top right hand corner, and the buttons that I coded in.

What I'm looking to do is create a keyboard shortcut. This Keyboard shortcut will then open up the "setup" form where different aspects of the application can be modified.

This is what I tried...

// In the Initialize Compenent section.
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Keyboard_Press);

// Then down below that...
private void Keyboard_Press(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
Setup frmSetup = new Setup();
frmSetup.Show();
}

This should open up a Setup Form whenever any key is pressed, no? However nothing happens. I even put a debug break in there, and the program never pauses to go into debug mode.

I guess that means that the form never trully ever had control.

Anyone have any ideas?
0
Comment
Question by:Decadre
  • 2
2 Comments
 
LVL 6

Accepted Solution

by:
ToFro earned 2000 total points
ID: 19577447
Set the KeyPreview property of the form to True, this will make the form intercept all Key Events so that the forms Events will fire first.
0
 
LVL 6

Assisted Solution

by:ToFro
ToFro earned 2000 total points
ID: 19577546
Your code would work perfectly, but you probably have a textbox, or some other control which has the focus and catches the keypresses before the form. If you set  this.KeyPreview = True;  ... it should work as you meant for it to.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question