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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Help on Key Press Event

Help on Key Press Event

Scheduled Pinned Locked Moved C#
questionhelp
3 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.
  • S Offline
    S Offline
    Saiyed Alam
    wrote on last edited by
    #1

    Hello friends I want to call a function on pressing Ctrl+S button. how can I do this? Thanking in Advance S.N.ALam

    P C 2 Replies Last reply
    0
    • S Saiyed Alam

      Hello friends I want to call a function on pressing Ctrl+S button. how can I do this? Thanking in Advance S.N.ALam

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      In a Winforms application? I'd make a Menu item and set Ctrl+S as the hot key. (Or I could be completely wrong; I ate a handfull of chocolate-covered espresso beans.)

      1 Reply Last reply
      0
      • S Saiyed Alam

        Hello friends I want to call a function on pressing Ctrl+S button. how can I do this? Thanking in Advance S.N.ALam

        C Offline
        C Offline
        Calla
        wrote on last edited by
        #3

        Just listen for the KeyPress event of the form (if it's in fact a WinForm application). When the key, or the key combination, is pressed just run your method. For instance:

        this.KeyPress += new System.Windows.Forms.KeyEventHandler(this.MyApp_KeyPress);

        private void MyApp_KeyPress(object sender, System.Windows.Forms.KeyEventArgs e)
        {
        if (e.KeyCode == Keys.F5)
        {
        this.MyMethod(); //MyMethod is the function you want to call
        return;
        }
        }

        private void MyMethod()
        {
        MessageBox.Show("MyMethod");
        }

        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