problem while trying to use form closing event [modified]
-
Dear All, I am trying to use form closing event for poping message for saving the data before closing the application with X at upper right corner. But my code is not working. my application closes without poping message box.
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
Dim a As Integer
a = MessageBox.Show("Are you sure to close", "Text", MessageBoxButtons.YesNo)
If a = 6 Then
'Application.Run()
e.Cancel = False
Else
' Application.Exit()
e.Cancel = True
End If
End SubThanks in advance........ :doh:
kisran
modified on Tuesday, September 16, 2008 2:40 AM
-
Dear All, I am trying to use form closing event for poping message for saving the data before closing the application with X at upper right corner. But my code is not working. my application closes without poping message box.
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
Dim a As Integer
a = MessageBox.Show("Are you sure to close", "Text", MessageBoxButtons.YesNo)
If a = 6 Then
'Application.Run()
e.Cancel = False
Else
' Application.Exit()
e.Cancel = True
End If
End SubThanks in advance........ :doh:
kisran
modified on Tuesday, September 16, 2008 2:40 AM
Hello Kisran, I am not sure whats wrong at your side. But your code works perfectly at my end. In case you are not able to resolve it, you can probably try this slight modified version of your code. BEGIN CODE
Dim dr As DialogResult = MessageBox.Show("Do you wish to close the Form", "Closing Form", MessageBoxButtons.YesNo) If dr = Windows.Forms.DialogResult.Yes Then e.Cancel = False Else e.Cancel = True End If
END CODE I hope this works. Regards, AllenAllen Smith ComponentOne LLC www.componentone.com
-
Hello Kisran, I am not sure whats wrong at your side. But your code works perfectly at my end. In case you are not able to resolve it, you can probably try this slight modified version of your code. BEGIN CODE
Dim dr As DialogResult = MessageBox.Show("Do you wish to close the Form", "Closing Form", MessageBoxButtons.YesNo) If dr = Windows.Forms.DialogResult.Yes Then e.Cancel = False Else e.Cancel = True End If
END CODE I hope this works. Regards, AllenAllen Smith ComponentOne LLC www.componentone.com
-
Dear All, I am trying to use form closing event for poping message for saving the data before closing the application with X at upper right corner. But my code is not working. my application closes without poping message box.
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
Dim a As Integer
a = MessageBox.Show("Are you sure to close", "Text", MessageBoxButtons.YesNo)
If a = 6 Then
'Application.Run()
e.Cancel = False
Else
' Application.Exit()
e.Cancel = True
End If
End SubThanks in advance........ :doh:
kisran
modified on Tuesday, September 16, 2008 2:40 AM
Try the following code : Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs) dim res res=msgbox("Do you want to close?",msgboxstyle.yesno,"sample") if res=vbno then e.cancel=false else e.cancel=true endif MyBase.OnClosing(e) Hope the above code will work...
-
Try the following code : Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs) dim res res=msgbox("Do you want to close?",msgboxstyle.yesno,"sample") if res=vbno then e.cancel=false else e.cancel=true endif MyBase.OnClosing(e) Hope the above code will work...
-
Still Not working Gagan............ Its giving compile time error on MyBase.OnClosing(e)
Error: OnClosing(e) is not a member of system.web.ui
can you Please Help me
kisran
modified on Tuesday, September 16, 2008 2:39 AM
Try again this one:
Protected Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)
dim res
res=msgbox("Do you want to close?",msgboxstyle.yesno,"sample")
if res=vbno then
e.cancel=false
else
e.cancel=true
endif
MyBase.OnClosing(e)
end sub
Put end sub after mybase.onclose(e) statement