I’m migrating a VB6 application, which has a subroutine that fires upon a QueryClose form event. As far as I can tell, this event no longer exists in System.Windows.Forms.
I tested with a breakpoint, and QueryClose does fire when you click the red ‘X’ in the upper right corner of the VB6 form, like the FormClosing event is supposed to do in VB.NET forms.
My question is: Does FormClosing have the closest equivalent functionality to QueryClose, or should I use a different event?
Private Sub UserForm_QueryClose(ByRef Cancel As Integer, ByRef CloseMode As Integer)
writeToLog()
writeRecentFoldersToFile(myTempFilePath & "Recent Folders.txt")
writePageSetupDefaultsToFile(myTempFilePath & "Page Setup.txt")
writeFormPositionToFile(myTempFilePath & "Form Position.txt")
userformKillTimer(Me, Me.Text)
End Sub
This code was originally VBA / VB6, which I put through ArtinSoft’s Visual Basic Upgrade Companion (VBUC). VBUC apparently didn’t think that there is an equivalent event, or isn’t smart enough to do that sort of conversion. FWIW, I’m using Microsoft Visual Basic 2010 Express.
I would put your code in FormClosed()
Your code doesn’t allow the user to cancel the form close, all it does is save some data.