Short Keys to Window Form
-
How do I catch for e.g. a + s (User want to save) to my Form (C#). _____________________________ ...and justice for all APe
-
How do I catch for e.g. a + s (User want to save) to my Form (C#). _____________________________ ...and justice for all APe
If you want to add a shortcut key combination to an event handler you could look at the: System.Windows.Forms.Shortcut. pre defined set. such as: System.Windows.Forms.Shortcut.CtrlS; for Ctrl + S. if you wanted to add this to an event handler for a menu bar for e.g. you would do this for an Exit item with Ctrl + X as shortcut keys: Menu.MenuItems.Add(new MenuItem("E&xit", new EventHandler(this.FileExit_Clicked), Shortcut.CtrlX)); where FileExit_Clicked is your event handling method.
-
How do I catch for e.g. a + s (User want to save) to my Form (C#). _____________________________ ...and justice for all APe
If you want to catch Ctrl+S you can override
ProcessCmdKey
in yourForm
derived class, like this...protected override bool ProcessCmdKey ( ref Message msg, Keys keyData ) { const int WM_KEYDOWN = 0x100; if ( msg.Msg == WM_KEYDOWN && keyData == ( Keys.Control | Keys.S ) ) { MessageBox.Show("You have pressed Ctrl+S"); return true; } return base.ProcessCmdKey( ref msg, keyData ); }
Hope that helps :)
“Accept that some days you are the pigeon, and some days you are the statue” -- David Brent Cheers, Will
-
If you want to catch Ctrl+S you can override
ProcessCmdKey
in yourForm
derived class, like this...protected override bool ProcessCmdKey ( ref Message msg, Keys keyData ) { const int WM_KEYDOWN = 0x100; if ( msg.Msg == WM_KEYDOWN && keyData == ( Keys.Control | Keys.S ) ) { MessageBox.Show("You have pressed Ctrl+S"); return true; } return base.ProcessCmdKey( ref msg, keyData ); }
Hope that helps :)
“Accept that some days you are the pigeon, and some days you are the statue” -- David Brent Cheers, Will
That made it!! Thanks! _____________________________ ...and justice for all APe