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. Handle key in all of application

Handle key in all of application

Scheduled Pinned Locked Moved C#
question
5 Posts 4 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.
  • M Offline
    M Offline
    MHASSANF
    wrote on last edited by
    #1

    hi i have the windows application and want when the user press esc the application exited but i don't know the focus now in the which control how can i do it ? MHF

    C M 2 Replies Last reply
    0
    • M MHASSANF

      hi i have the windows application and want when the user press esc the application exited but i don't know the focus now in the which control how can i do it ? MHF

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can set a keypreview property on the form, I thought, which means the form gets to preview all keys.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      M 1 Reply Last reply
      0
      • C Christian Graus

        You can set a keypreview property on the form, I thought, which means the form gets to preview all keys.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        M Offline
        M Offline
        MHASSANF
        wrote on last edited by
        #3

        is there some things like this to mouse events ?? mHF

        S 1 Reply Last reply
        0
        • M MHASSANF

          is there some things like this to mouse events ?? mHF

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          MHASSANF wrote:

          is there some things like this to mouse events ??

          As far as I know there is nothing as easy as simply enabling KeyPreview. Instead you'll have to use hooks that however are well covered by many internet resources. You can start from this CP article Using Hooks from C#[^]


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          1 Reply Last reply
          0
          • M MHASSANF

            hi i have the windows application and want when the user press esc the application exited but i don't know the focus now in the which control how can i do it ? MHF

            M Offline
            M Offline
            Muammar
            wrote on last edited by
            #5
                private void YourForm\_KeyDown(object sender, KeyEventArgs e)
                {
                    if(e.KeyCode.ToString()=="Escape")
                    Application.Exit();
                }
            

            Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)

            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