Closing event

N

N! Xau

Hi,

I want to avoid an user closes the form clicking on the upper right
side "X" button.
So, for the Closing event, I set:
e.cancel = true

The problem is, this way the user can't even close the form using the
appropriate button Exit (a button built on the form).
How can I link a click on Exit to set e.cancel = false, keeping it true
otherwise?

thanks

N! Xau
keep in mind the power of Antani
http://ilovemiliofede.altervista.org
 
C

Chris

N! Xau said:
Hi,

I want to avoid an user closes the form clicking on the upper right
side "X" button.
So, for the Closing event, I set:
e.cancel = true

The problem is, this way the user can't even close the form using the
appropriate button Exit (a button built on the form).
How can I link a click on Exit to set e.cancel = false, keeping it true
otherwise?

thanks

N! Xau
keep in mind the power of Antani
http://ilovemiliofede.altervista.org

Why not hide the control box for the form so they don't see the "X"
button?

Otherwise in your exit button set a boolean variable to true that allows
the form to exit.

Sub Exit_Click(....) handles Exit.Click
blAllowExit = True
End Sub

In the form.closing event:
if not blAllowExit then
e.cancel = false
End if

Hope it helps
Chris
 
H

Herfried K. Wagner [MVP]

N! Xau said:
I want to avoid an user closes the form clicking on the upper right
side "X" button.
So, for the Closing event, I set:
e.cancel = true

The problem is, this way the user can't even close the form using the
appropriate button Exit (a button built on the form).
How can I link a click on Exit to set e.cancel = false, keeping it true
otherwise?

Add the code below to your form in order to disable the "X" button:

\\\
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
Const CS_DBLCLKS As Int32 = &H8
Const CS_NOCLOSE As Int32 = &H200
cp.ClassStyle = CS_DBLCLKS Or CS_NOCLOSE
Return cp
End Get
End Property
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top