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. detecting keystrokes...How?

detecting keystrokes...How?

Scheduled Pinned Locked Moved C#
questionhelp
3 Posts 2 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.
  • T Offline
    T Offline
    TheCardinal
    wrote on last edited by
    #1

    I have created a windows form application... the problem is that when the keyboard keystroke combination ALT-F4 was press my application quits. How can i stop the user from hitting the ALT-F4 key to terminate my application? thanks in advance :)

    N 1 Reply Last reply
    0
    • T TheCardinal

      I have created a windows form application... the problem is that when the keyboard keystroke combination ALT-F4 was press my application quits. How can i stop the user from hitting the ALT-F4 key to terminate my application? thanks in advance :)

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      You need to override the ProcessDialogKey method of the form. The follow code will allow you to block ALT-F4 from closing your application.

          protected override bool ProcessDialogKey(Keys keyData)
          {
              Keys altf4 = Keys.Alt | Keys.F4;
              if (keyData == altf4)
              {
                  return true;
              }
              return base.ProcessDialogKey(keyData);
          }
      

      - Nick Parker Microsoft MVP - Visual C#
      My Blog | My Articles

      T 1 Reply Last reply
      0
      • N Nick Parker

        You need to override the ProcessDialogKey method of the form. The follow code will allow you to block ALT-F4 from closing your application.

            protected override bool ProcessDialogKey(Keys keyData)
            {
                Keys altf4 = Keys.Alt | Keys.F4;
                if (keyData == altf4)
                {
                    return true;
                }
                return base.ProcessDialogKey(keyData);
            }
        

        - Nick Parker Microsoft MVP - Visual C#
        My Blog | My Articles

        T Offline
        T Offline
        TheCardinal
        wrote on last edited by
        #3

        It works like a charm!:) Excellent Thanks a lot for the help, Nick :)

        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