Dodgeram01 Posted June 24, 2002 Posted June 24, 2002 Does anyone know the code to make allow the user to quit the program? Just placing "End" doesn't work for me. Well, for me it does, but on anyone else's computer, it won't let the program start, giving an error. I had a little problem with the end yesterday when I had a button which would close it. It said something about unmanaged code. I moved the end into a file menu, and it seemed to work fine. My beta testers though can't run it when the end is in the file menu (didn't have them test with it for the button), but it works fine when it's not in the menu. Any ideas will be appreciated. Quote Dodge Grab Life By The Horns
*Gurus* Derek Stone Posted June 24, 2002 *Gurus* Posted June 24, 2002 Application.Exit() Good Luck -CL Quote Posting Guidelines
*Gurus* Thinker Posted June 24, 2002 *Gurus* Posted June 24, 2002 If you have any code in Closing or Closed events on your form(s), you need to unload your forms first, because Exit() will bypass raising these events. Quote Posting Guidelines
*Gurus* Derek Stone Posted June 24, 2002 *Gurus* Posted June 24, 2002 Or you can unload the windows within the ApplicationExit event. Up to you. Good Luck -CL Quote Posting Guidelines
Dodgeram01 Posted June 24, 2002 Author Posted June 24, 2002 Thanks! Now you would have thought that for me searching about that yesterday for prolly 15 to 30 minutes I woudl have found something. This board is great! Thanks again. Quote Dodge Grab Life By The Horns
Guest holtzy Posted July 24, 2002 Posted July 24, 2002 I'm have trouble exiting the entire program. The code... Application.Exit() isn't working. In VBA I used Quit. Is there any reason I couldn't use this code? Quote
*Gurus* Derek Stone Posted July 24, 2002 *Gurus* Posted July 24, 2002 If you don't have a window that inherits from System.Windows.Forms then you won't be able to use the Application class. Quote Posting Guidelines
Leaders dynamic_sysop Posted November 13, 2003 Leaders Posted November 13, 2003 i built this example a while back , if you wish to make sure all forms get closed, then close the main form.... Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As String, ByVal lParam As String) As Integer Private Const WM_CLOSE As Integer = &H10 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim frmTypes() As Type = Reflection.Assembly.GetExecutingAssembly.GetTypes Dim fType As Type Dim hwnd As Integer Try For Each fType In frmTypes If Not fType.Name = Me.Name Then '/// make sure we dont accidently close the main Form. hwnd = FindWindow(vbNullString, fType.Name) If Not hwnd = 0 Then PostMessage(hwnd, WM_CLOSE, vbNullString, vbNullString) End If End If Next Catch ex As Exception MessageBox.Show(ex.Message) Finally MyBase.Close() '/// now all other Form's are closed , we can close the main Form. End Try End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.