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. Capture Close Button

Capture Close Button

Scheduled Pinned Locked Moved C#
csharpvisual-studioquestion
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.
  • P Offline
    P Offline
    paas
    wrote on last edited by
    #1

    I am using Visual Studio 2005 to write a C# program. And I am wondering if anyone tell me if there is a programattic way to differentiate when a form is being closed via the Close() method as opposed to being closed via a user clicking on the control box 'x'? The CloseReason seems to be the same for either one, and I would like to know which 'Close' is occurring if possible. Thank You...

    G P P 3 Replies Last reply
    0
    • P paas

      I am using Visual Studio 2005 to write a C# program. And I am wondering if anyone tell me if there is a programattic way to differentiate when a form is being closed via the Close() method as opposed to being closed via a user clicking on the control box 'x'? The CloseReason seems to be the same for either one, and I would like to know which 'Close' is occurring if possible. Thank You...

      G Offline
      G Offline
      Gareth H
      wrote on last edited by
      #2

      paas, I dont think there is a difference. However, when calling the form.Close(); method, you could set a flag and then in the OnClosing event, handle that flag and do whatever you want. Regards, Gareth.

      1 Reply Last reply
      0
      • P paas

        I am using Visual Studio 2005 to write a C# program. And I am wondering if anyone tell me if there is a programattic way to differentiate when a form is being closed via the Close() method as opposed to being closed via a user clicking on the control box 'x'? The CloseReason seems to be the same for either one, and I would like to know which 'Close' is occurring if possible. Thank You...

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #3

        Look up the OnClosing event handler, you can handle the close from there.

        "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

        1 Reply Last reply
        0
        • P paas

          I am using Visual Studio 2005 to write a C# program. And I am wondering if anyone tell me if there is a programattic way to differentiate when a form is being closed via the Close() method as opposed to being closed via a user clicking on the control box 'x'? The CloseReason seems to be the same for either one, and I would like to know which 'Close' is occurring if possible. Thank You...

          P Offline
          P Offline
          paas
          wrote on last edited by
          #4

          Thanks everyone for the replies. Unfortunately my initial message was not as detailed as it should have been. I know about the FormClosing event and how I could trap a flag I set before programtically executing a Form.Close(). However, what I really need to know is the difference between the closes that can be executed on the title bar. Either the 'x' close in the right corner, or the 'Close' that can be executed from the dropdown appears when you click in the left corner (on the icon). Can those be differentiated in the Closing event?

          D 1 Reply Last reply
          0
          • P paas

            Thanks everyone for the replies. Unfortunately my initial message was not as detailed as it should have been. I know about the FormClosing event and how I could trap a flag I set before programtically executing a Form.Close(). However, what I really need to know is the difference between the closes that can be executed on the title bar. Either the 'x' close in the right corner, or the 'Close' that can be executed from the dropdown appears when you click in the left corner (on the icon). Can those be differentiated in the Closing event?

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

            Not as far as I can tell. Even if overriding WndProc the same data is sent for both. m.Msg is WM_SYSCOMMAND (0x0112) m.WParam is SC_CLOSE (0xf060)

            Dave

            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