Register shortcuts-display and hide windows
// Register the hotkey API
[Dllimport ("USER32")]
Public static extern bool registerhotkey (intptr hwnd, int ID, uint control, keys VK );
// API for removing the registration hotkey
[Dllimport ("USER32")]
Public static extern bool unregisterhotkey (intptr hwnd, int ID );
Private void form1_load (Object sender, system. eventargs E)
{
Registerhotkey (this. Handle, 11, 2, keys. Q); // register the hotkey
Registerhotkey (this. Handle, 22, 2, keys. );
}
Private void form=formclosed (Object sender, formclosedeventargs E)
{
Unregisterhotkey (this. Handle, 11); // unregister the hotkey
Unregisterhotkey (this. Handle, 22 );
}
Protected override void wndproc (ref message m)
{
Switch (M. msg)
{
Case 0x0312: // hotkey message
If (M. wparam. tostring () = "11") // press Ctrl + Q to hide the window.
{
This. Hide ();
}
Else if (M. wparam. tostring () = "22") // press Ctrl + A to display the window
{
This. Visible = true;
}
Break;
}
Base. wndproc (ref m );
}