Home All Groups Group Topic Archive Search About
Author
29 Jun 2005 2:30 PM
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

Author
29 Jun 2005 2:55 PM
Chris
N! Xau wrote:
Show quoteHide quote
> 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
Author
29 Jun 2005 3:40 PM
Herfried K. Wagner [MVP]
"N! Xau" <n***@hotmail.com> schrieb:
> 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
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>