|
-
Oct 17th, 2012, 11:58 AM
#1
Thread Starter
Addicted Member
Closing the App
This probably has a simple explaination, but it simply evades me at the moment. When I am trying to close
my application, I use Application.Exit, but the problem is that when it reaches this statement, it then goes thru
the FrmMain_FormClosing a second time, so if you watch Static count, it displays the messagebox indicating that
the formClosing event has run twice. I have boldened the most relevant code. It has been so long since I have
dealt with this type of code, I just do not remember how to get it working correctly!
Code:
Private Sub FrmMain_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim FHS As New AppFileHistory
Try
' If no text in textbox, close application
If Me.RTBMain.Text = "" Then
System.Windows.Forms.Application.Exit()
End
Exit Sub
End If
' Determine if text has changed in the textbox by comparing to original text.
If (Me.RTBMain.Text <> strMyOriginalText) Or Properties.pBoolRTBModified = True Then
' Display a MsgBox asking the user to save changes or abort.
messageboxYesNoCancelShown = True
Select Case MsgBox("Do you want to save changes to your text?", MsgBoxStyle.YesNoCancel)
Case MsgBoxResult.Yes
Cursor.Current = Cursors.WaitCursor
If Properties.pStrCurrentFilePath.Length > 0 Then
Me.btnSave.PerformClick()
Else
ToolStripMenuItemSaveAs_Click(Me, e)
Exit Sub
End If
Cursor.Current = Cursors.Default
Case MsgBoxResult.Cancel
Exit Sub
Case MsgBoxResult.No
Exit Sub
End Select
End If
' DO other things
Static count As Integer
count = count + 1
If count > 1 Then
MsgBox("Double trouble . . . ")
End If
Application.Exit()
End
Catch ex As Exception
FIO.reportError("Error:" & ex.StackTrace & ". . . ." & vbCrLf & Err.Description & vbCrLf & " Exception: " & ex.ToString)
End Try
End Sub
Private Sub btnClose_Click(sender As Object, e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
.
We must question the story logic of having an all-knowing all-powerful God, who creates faulty Humans, and then blames them for his own mistakes.
GENE RODDENBERRY
.
http://www.tachufind.com
.
Tags for this Thread
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
|