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. Close the form programmaticaly.

Close the form programmaticaly.

Scheduled Pinned Locked Moved C#
csharphelpquestion
11 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.
  • T Offline
    T Offline
    tingu
    wrote on last edited by
    #1

    I have created a visual C# windows application project with one form. I have removed the close x button by setting ControBox=False. Then if I use this.close() method to close the form I get error. It doesn't show any error message but shows dialog "application has top close...". I was under the impression that it was happening due to Application.Run method. But can anyone please suggest a solution to this?

    C L J 3 Replies Last reply
    0
    • T tingu

      I have created a visual C# windows application project with one form. I have removed the close x button by setting ControBox=False. Then if I use this.close() method to close the form I get error. It doesn't show any error message but shows dialog "application has top close...". I was under the impression that it was happening due to Application.Run method. But can anyone please suggest a solution to this?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Do you have any other threads running ? this.Close() should work just fine.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      T 1 Reply Last reply
      0
      • C Christian Graus

        Do you have any other threads running ? this.Close() should work just fine.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

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

        No, I don't think so. It is a very simple application with 2 functions. Is there a way to figure out if any other thread is running? Thanks.

        1 Reply Last reply
        0
        • T tingu

          I have created a visual C# windows application project with one form. I have removed the close x button by setting ControBox=False. Then if I use this.close() method to close the form I get error. It doesn't show any error message but shows dialog "application has top close...". I was under the impression that it was happening due to Application.Run method. But can anyone please suggest a solution to this?

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #4

          harsha1305 wrote:

          Then if I use this.close()

          Application.Exit();

          led mike

          C 1 Reply Last reply
          0
          • L led mike

            harsha1305 wrote:

            Then if I use this.close()

            Application.Exit();

            led mike

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            *grin* I knew there was an Application. method, but couldn't recall. Does that do a hard close, or still post WM_CLOSE to all windows ?

            Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

            L P 2 Replies Last reply
            0
            • C Christian Graus

              *grin* I knew there was an Application. method, but couldn't recall. Does that do a hard close, or still post WM_CLOSE to all windows ?

              Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #6

              Christian Graus wrote:

              Does that do a hard close, or still post WM_CLOSE to all windows ?

              Who knows, it's .NET so it might all change from version to the next anyway! :-> At one point I do believe I read something that said it does stop all the threads in that process. But again that was some time ago so now, on what versions, I don't really know or probably care. When I care about those types of details I will fall back to C++ native development. Like someone said the other day, C# is VB in wolfs clothing. I added, yes just like Delphi and Java. Really it's the .NET platform as opposed to the languages. When one of the main purposes of the platform is to hide the details of how stuff works from the developers it's difficult to remain interested in them. The platform is fine for many projects but not necessarily for any project. I eat my peas with honey I've done it all my life It makes the peas taste funny But it keeps them on my knife

              led mike

              1 Reply Last reply
              0
              • C Christian Graus

                *grin* I knew there was an Application. method, but couldn't recall. Does that do a hard close, or still post WM_CLOSE to all windows ?

                Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

                P Offline
                P Offline
                Pete OHanlon
                wrote on last edited by
                #7

                It tells the message pumps to terminate and then closes the app windows.

                Deja View - the feeling that you've seen this post before.

                My blog | My articles

                T 1 Reply Last reply
                0
                • P Pete OHanlon

                  It tells the message pumps to terminate and then closes the app windows.

                  Deja View - the feeling that you've seen this post before.

                  My blog | My articles

                  T Offline
                  T Offline
                  tingu
                  wrote on last edited by
                  #8

                  I should Application.Exit() be called in main()? If so I tried it, but shows the same error.

                  T 1 Reply Last reply
                  0
                  • T tingu

                    I should Application.Exit() be called in main()? If so I tried it, but shows the same error.

                    T Offline
                    T Offline
                    tingu
                    wrote on last edited by
                    #9

                    I tried this.close() again and got system.objectdisposedexception exception. So I called this.dispose() before this.close(), but still the same exception. What is the proper code for closing the form? Thanks.

                    A 1 Reply Last reply
                    0
                    • T tingu

                      I tried this.close() again and got system.objectdisposedexception exception. So I called this.dispose() before this.close(), but still the same exception. What is the proper code for closing the form? Thanks.

                      A Offline
                      A Offline
                      Anthony Mushrow
                      wrote on last edited by
                      #10

                      That is the proper code for closing a form. You shouldn't be getting any error. Try putting the 'X' back on and close your form, if you still get the error then you can be absolutely certain that it has nothing to do with your closing code.

                      My current favourite word is: Nipple!

                      -SK Genius

                      1 Reply Last reply
                      0
                      • T tingu

                        I have created a visual C# windows application project with one form. I have removed the close x button by setting ControBox=False. Then if I use this.close() method to close the form I get error. It doesn't show any error message but shows dialog "application has top close...". I was under the impression that it was happening due to Application.Run method. But can anyone please suggest a solution to this?

                        J Offline
                        J Offline
                        jasper018
                        wrote on last edited by
                        #11

                        If closing the form is to end the application you could use: Application.Exit();

                        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