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. How to prevent cnt+f4 key,,,?

How to prevent cnt+f4 key,,,?

Scheduled Pinned Locked Moved C#
csharpgame-devtutorialquestion
5 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.
  • P Offline
    P Offline
    Pankaj Joshi
    wrote on last edited by
    #1

    Hello experts... I am developing an game using desktop application in C#.net 2005. In that I have 3 forms (No MDI form). I want to show form1 then form2 and then form3. But if user press cntl+f4 key form goes close and second forms show how to prevent this..? I also have close button on each form.

    Regards Pankaj Joshi

    C D 2 Replies Last reply
    0
    • P Pankaj Joshi

      Hello experts... I am developing an game using desktop application in C#.net 2005. In that I have 3 forms (No MDI form). I want to show form1 then form2 and then form3. But if user press cntl+f4 key form goes close and second forms show how to prevent this..? I also have close button on each form.

      Regards Pankaj Joshi

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Handle the Closing event on the form, the event arguments will have a Cancel property. Set that Cancel property to true.


      Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website

      1 Reply Last reply
      0
      • P Pankaj Joshi

        Hello experts... I am developing an game using desktop application in C#.net 2005. In that I have 3 forms (No MDI form). I want to show form1 then form2 and then form3. But if user press cntl+f4 key form goes close and second forms show how to prevent this..? I also have close button on each form.

        Regards Pankaj Joshi

        D Offline
        D Offline
        DannyAdler
        wrote on last edited by
        #3

        1. Set the form's KeyPreview property to true. 2. Add a KeyDown event to the form like this: private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == (int)Keys.F4 && e.Modifiers == Keys.Control) { e.SuppressKeyPress = true; } } That's it. Hope it'll help. Danny

        P 1 Reply Last reply
        0
        • D DannyAdler

          1. Set the form's KeyPreview property to true. 2. Add a KeyDown event to the form like this: private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == (int)Keys.F4 && e.Modifiers == Keys.Control) { e.SuppressKeyPress = true; } } That's it. Hope it'll help. Danny

          P Offline
          P Offline
          Pankaj Joshi
          wrote on last edited by
          #4

          Hello DannyAdler sir, This is working fine. Thannks for the help. I only have one question .. Is their any problem to using that code.? I don't think so... But if any, please tell me points to be remember while using this code.

          Regards Pankaj Joshi

          D 1 Reply Last reply
          0
          • P Pankaj Joshi

            Hello DannyAdler sir, This is working fine. Thannks for the help. I only have one question .. Is their any problem to using that code.? I don't think so... But if any, please tell me points to be remember while using this code.

            Regards Pankaj Joshi

            D Offline
            D Offline
            DannyAdler
            wrote on last edited by
            #5

            Two things I can think of: 1. After setting the KeyPreview property to true, ALL the key-down events will first go through this function. 2. The CTRL-F4 will never work on that window, as long as the key-down is supressed in the if statement. Just to keep in mind. Danny

            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