|
-
Aug 6th, 2006, 09:48 PM
#1
Thread Starter
Lively Member
Simple button?
I am a newbie to coding. But I have learned so much already jsut by reading post and other documents on line. I have not gotten a book yet for VB 2005
I am looking for the code to create a cancel button to close the window and cancel any process that is running. Thanks
-
Aug 6th, 2006, 10:04 PM
#2
Hyperactive Member
Re: Simple button?
You can use Me.Close to close a form, or End to end the whole program. In terms of cancelling processes, if you mean within your program, ending the program may do what you want. If you have code that takes a long time to execute, then you could declare a global boolean variable, and if it is true keep going in the loop/code, otherwise exit the program. You would change it to false only when you want the program to exit (this is not the best way - search google and msdn for other solutions, see jmcilhinney's signature for many other resources, and finally, I suggest this site).
-
Aug 6th, 2006, 10:05 PM
#3
Fanatic Member
Re: Simple button?
It depends what you mean by "cancel any process that is running". If you want a cancel button to close a form then place:
...in the buttons Click event. You can also designate the button as the forms Cancel button using the form's CancelButton property. Just select the button in the drop-down list that appears.
-
Aug 6th, 2006, 10:06 PM
#4
Fanatic Member
Re: Simple button?
If you want to exit an application it is better practice to use:
... rather than End.
-
Aug 7th, 2006, 02:10 AM
#5
Re: Simple button?
the best way is to use Me.Close to close the main form, or to code it so that Sub Main hits the "End Sub" line
using "End" is the worst way to end your app and Application.Exit does terminate the app, but it doesnt allow for any cleanup code to run
-
Aug 7th, 2006, 02:15 AM
#6
Re: Simple button?
 Originally Posted by JuggaloBrotha
Application.Exit does terminate the app, but it doesnt allow for any cleanup code to run
Actually, that's not the case in .NET 2.0. The FormClosing and FormClosed events were specifically added for that reason. If you call Application.Exit then the Closing and Closed events are not raised. As they were all you had in .NET 1.x you were scuppered. The FormClosing and FormClosed events ARE raised on open forms when Application.Exit is called, which is how it should be. The old events have been retianed and the new ones added for backward-compatibility, rather than simply changing the behaviour of the existing events and possibly breaking existing code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|