How to cancel the unload event of a form? I have this code in vb 6 and it is working: -
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
-
If MsgBox("Are you sure you want to exit system?", vbYesNo, "Exit System") = vbYes Then
-
Unload Me
-
Else
-
Cancel = 1
-
End If
-
End Sub
-
I converted the codes to vb .net but I failed to make it: - Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
-
If MessageBox.Show("Are you sure you want to exit system?", "Exit System", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
-
Global.System.Windows.Forms.Application.Exit()
-
Else
-
Exit Sub
-
End If
-
End Sub
Rey Sean
3 2951
How to cancel the unload event of a form? I have this code in vb 6 and it is working: -
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
-
If MsgBox("Are you sure you want to exit system?", vbYesNo, "Exit System") = vbYes Then
-
Unload Me
-
Else
-
Cancel = 1
-
End If
-
End Sub
-
I converted the codes to vb .net but I failed to make it: - Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
-
If MessageBox.Show("Are you sure you want to exit system?", "Exit System", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
-
Global.System.Windows.Forms.Application.Exit()
-
Else
-
Exit Sub
-
End If
-
End Sub
Rey Sean
Use the FormClosing eventargs -
If MessageBox.Show("Are you sure?", "Close?", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then
-
e.Cancel = True
-
Else
-
e.Cancel = False
-
End If
-
I just added this line.
But now, the problem is, it showing the message dialog box twice when I clicked the Yes button. What may be the problem? What do you think?
Rey Sean
Do you have two event handlers assigned to the event?
It should also be noted that you need to be looking at the e.CloseReason property too make sure it's not CloseReason.WindowsShutDown or CloseReason.TaskManagerClosing. You should not popup your messagebox if it's one those two.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MS |
last post by:
Just a general question here re VBA.
Can anyone explain the differences between "!" and "." when refering to a control?
eg Me!TxtBox and Me.TxtBox.
What is difference between "+" and "&"...
|
by: peter hansen |
last post by:
I tried a couple of weeks ago but I'll try again :D
I old VB6-days it was possible to unload a form bu using the Unload(Form)
command.
I have tried the Close-function but it'll unload the entire...
|
by: devonknows |
last post by:
Ok, i posted about forcing a form to unload, now since ive implemented that, when check1.value = true, when you close the form, it doesnt unload,
when check1.value = false, it unloads perfectly and...
|
by: Ronald S. Cook |
last post by:
We have a Windows app that has one main form (a shell, sort of). We then
load user controls into a panel on the form depending on what the user has
selected.
Our current code to unload the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |