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. Uncloseable window

Uncloseable window

Scheduled Pinned Locked Moved C#
question
8 Posts 6 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.
  • R Offline
    R Offline
    ruanr
    wrote on last edited by
    #1

    Hi, I have a modal dialog that I don't want the user to close via the close button, how do I disable it? Thanks

    S R L 3 Replies Last reply
    0
    • R ruanr

      Hi, I have a modal dialog that I don't want the user to close via the close button, how do I disable it? Thanks

      S Offline
      S Offline
      Stevo Z
      wrote on last edited by
      #2

      Override the OnClosing event and set the Cancel memeber of that event argument to true. Rember that just disabling close button won't do the job, user can still use ALT + F4 :) . Stevo

      R 1 Reply Last reply
      0
      • S Stevo Z

        Override the OnClosing event and set the Cancel memeber of that event argument to true. Rember that just disabling close button won't do the job, user can still use ALT + F4 :) . Stevo

        R Offline
        R Offline
        ruanr
        wrote on last edited by
        #3

        wow, all that effort :/ in swing I remember just having to set a field :/ Thanks :)

        1 Reply Last reply
        0
        • R ruanr

          Hi, I have a modal dialog that I don't want the user to close via the close button, how do I disable it? Thanks

          R Offline
          R Offline
          Rahul RK
          wrote on last edited by
          #4

          He you can do it by 2 methods, First one is just capture closing event of that form and make e.cancel = true; or second method is you disable closing button using following code, You have to use win32 dll. const int SC_CLOSE = 0xF060; const int MF_BYCOMMAND = 0x0; [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr RemoveMenu(IntPtr menuHwnd, int position, int flags ); [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr GetSystemMenu(IntPtr hwnd, int bRevert); public static void EnableApplicationClose( System.Windows.Forms.Form form, bool val ) { IntPtr menu = GetSystemMenu( form.Handle, val ? 1 : 0 ); if ( !val && menu != IntPtr.Zero ) RemoveMenu(menu, SC_CLOSE, MF_BYCOMMAND ); else { // needed when enabling the app close box to force it to redraw. form.Enabled = false; form.Enabled = true; } } Rahul Kulkarni

          R 1 Reply Last reply
          0
          • R Rahul RK

            He you can do it by 2 methods, First one is just capture closing event of that form and make e.cancel = true; or second method is you disable closing button using following code, You have to use win32 dll. const int SC_CLOSE = 0xF060; const int MF_BYCOMMAND = 0x0; [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr RemoveMenu(IntPtr menuHwnd, int position, int flags ); [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr GetSystemMenu(IntPtr hwnd, int bRevert); public static void EnableApplicationClose( System.Windows.Forms.Form form, bool val ) { IntPtr menu = GetSystemMenu( form.Handle, val ? 1 : 0 ); if ( !val && menu != IntPtr.Zero ) RemoveMenu(menu, SC_CLOSE, MF_BYCOMMAND ); else { // needed when enabling the app close box to force it to redraw. form.Enabled = false; form.Enabled = true; } } Rahul Kulkarni

            R Offline
            R Offline
            ruanr
            wrote on last edited by
            #5

            I think I'll opt for method 1 :)

            1 Reply Last reply
            0
            • R ruanr

              Hi, I have a modal dialog that I don't want the user to close via the close button, how do I disable it? Thanks

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Choose a window style without close button: FormBorderStyle.None Having a button (or any GUI element) visible but turned off (without a visual clue) is not good practice. :)

              Luc Pattyn [My Articles] [Forum Guidelines]

              V 1 Reply Last reply
              0
              • L Luc Pattyn

                Choose a window style without close button: FormBorderStyle.None Having a button (or any GUI element) visible but turned off (without a visual clue) is not good practice. :)

                Luc Pattyn [My Articles] [Forum Guidelines]

                V Offline
                V Offline
                Vasudevan Deepak Kumar
                wrote on last edited by
                #7

                Luc Pattyn wrote:

                Having a button (or any GUI element) visible but turned off (without a visual clue) is not good practice.

                Yup! The entity that can not be used drives the user mad. :mad: :)

                Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                D 1 Reply Last reply
                0
                • V Vasudevan Deepak Kumar

                  Luc Pattyn wrote:

                  Having a button (or any GUI element) visible but turned off (without a visual clue) is not good practice.

                  Yup! The entity that can not be used drives the user mad. :mad: :)

                  Vasudevan Deepak Kumar Personal Homepage Tech Gossips

                  D Offline
                  D Offline
                  Dan Neely
                  wrote on last edited by
                  #8

                  and the dialog that can't be closed drives the user to kill process and uninstall. :mad: X|

                  -- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer

                  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