Closing event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • N! Xau

    #1

    Closing event

    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


  • Chris

    #2
    Re: Closing event

    N! Xau wrote:[color=blue]
    > 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
    >[/color]

    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

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Closing event

      "N! Xau" <nxau@hotmail.c om> schrieb:[color=blue]
      > 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?[/color]

      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.CreatePa rams
      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/>

      Comment

      Working...