Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I am creating a desktop application which invokes a pop up form after a specific time interval.I want to add a functionality that if a shortcut key is pressed the form should pop up...plz help.
Posted
Updated 1-Aug-11 21:01pm
v3
Comments
BillWoodruff 2-Aug-11 0:46am    
Is this for WinForms, or WPF ?
Sergey Alexandrovich Kryukov 2-Aug-11 0:50am    
WinForms I guess. In WPF windows are not called "forms".
--SA
AC777 2-Aug-11 1:00am    
Its a windows forms app

1 solution

If you want the Form itself to intercept a shortcut key, before any of the Controls on the Form get the Key Event (Pressed, Down, Up), then: set the the KeyPreview Property of the Form to 'true, and write the appropriate form key-event handler in which, if your choice of key-combinations and modifiers (shift, alt, control) is active, you 'Show your pop-up.

Your question implies a Timer being used; I'm not clear if the Timer is something operating independently of the shortcut-key being received, but you can control the delay between shortcut received and appearance of the pop-up, by using a Timer, if that's what you mean.

Note the distinction between 'closing a Form, or UserControl, which destroys the instance of that Form or UserControl, and 'hiding a Form or UserControl which does not destroy the instance, and allows you to re-use it, via the 'Show method.

My guess is you are describing a scenario where you do want to use 'Hide rather than 'Close: i.e., you do not wish to re-create the pop-up instance (via 'new, or Activator.CreateInstance) every time you need it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900