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. Disabling "X" button in WinForm

Disabling "X" button in WinForm

Scheduled Pinned Locked Moved C#
tutorialquestion
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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    How to disable "X" button at the top right of winform ? Thanks...

    N A 2 Replies Last reply
    0
    • L Lost User

      How to disable "X" button at the top right of winform ? Thanks...

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      ControlBox = false

      1 Reply Last reply
      0
      • L Lost User

        How to disable "X" button at the top right of winform ? Thanks...

        A Offline
        A Offline
        Anh_Tuan
        wrote on last edited by
        #3

        Depend on how you would like for it to behave 1. Handle form closing event, set e.Cancel to true Or 2. Use Win32 API // constants for menu manipulation 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 ); 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; } } [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr GetSystemMenu(IntPtr hwnd, int bRevert); Jup -- modified at 9:03 Friday 7th July, 2006

        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