Close the form programmaticaly.
-
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?
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 )
-
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 )
-
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?
-
*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 )
-
*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 )
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
-
*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 )
It tells the message pumps to terminate and then closes the app windows.
Deja View - the feeling that you've seen this post before.
-
It tells the message pumps to terminate and then closes the app windows.
Deja View - the feeling that you've seen this post before.
-
I should Application.Exit() be called in main()? If so I tried it, but shows the same error.
-
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.
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
-
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?