Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Short Keys to Window Form

Short Keys to Window Form

Scheduled Pinned Locked Moved C#
csharpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anderslundsgard
    wrote on last edited by
    #1

    How do I catch for e.g. a + s (User want to save) to my Form (C#). _____________________________ ...and justice for all APe

    D K 2 Replies Last reply
    0
    • A anderslundsgard

      How do I catch for e.g. a + s (User want to save) to my Form (C#). _____________________________ ...and justice for all APe

      D Offline
      D Offline
      Darren_
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • A anderslundsgard

        How do I catch for e.g. a + s (User want to save) to my Form (C#). _____________________________ ...and justice for all APe

        K Offline
        K Offline
        kasik
        wrote on last edited by
        #3

        If you want to catch Ctrl+S you can override ProcessCmdKey in your Form 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

        A 1 Reply Last reply
        0
        • K kasik

          If you want to catch Ctrl+S you can override ProcessCmdKey in your Form 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

          A Offline
          A Offline
          anderslundsgard
          wrote on last edited by
          #4

          That made it!! Thanks! _____________________________ ...and justice for all APe

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups