Confirm Exit in a Mdi form?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iDesmet

    Confirm Exit in a Mdi form?

    Hallo,

    I have a Mdi form in which I show a MessageBox if the user tries to
    close it. If the user clicks YES, then the form closes; if it clicks
    NO then it aborts.

    I added the following lines in my form Closing event:

    If MessageBox.Show ("Are you sure do you want to exit?", gsAppName,
    MessageBoxButto ns.YesNo, MessageBoxIcon. Question,
    MessageBoxDefau ltButton.Button 2) = Windows.Forms.D ialogResult.Yes Then
    Me.Close()
    End If

    But it doesn't work. So I was wondering if someone is so kind to point
    me to the error.

    I'm using VB.NET

    Thanks in advance.

    PS My apologies for my bad english.

    Best Regards,
    David Desmet
  • kimiraikkonen

    #2
    Re: Confirm Exit in a Mdi form?

    On Jun 11, 12:23 pm, iDesmet <idesmet.w...@g mail.comwrote:
    Hallo,
    >
    I have a Mdi form in which I show a MessageBox if the user tries to
    close it. If the user clicks YES, then the form closes; if it clicks
    NO then it aborts.
    >
    I added the following lines in my form Closing event:
    >
    If MessageBox.Show ("Are you sure do you want to exit?", gsAppName,
    MessageBoxButto ns.YesNo, MessageBoxIcon. Question,
    MessageBoxDefau ltButton.Button 2) = Windows.Forms.D ialogResult.Yes Then
    Me.Close()
    End If
    >
    But it doesn't work. So I was wondering if someone is so kind to point
    me to the error.
    >
    I'm using VB.NET
    >
    Thanks in advance.
    >
    PS My apologies for my bad english.
    >
    Best Regards,
    David Desmet
    David,
    Try this one:

    Private Sub Form1_Closing(B yVal sender As System.Object, ByVal e As
    System.Componen tModel.CancelEv entArgs) Handles MyBase.Closing

    If MessageBox.Show ("Are you sure do you want to exit?",
    "gsAppName",Mes sageBoxButtons. YesNo,
    MessageBoxIcon. Question,Messag eBoxDefaultButt on.Button2) =
    Windows.Forms.D ialogResult.Yes Then
    Application.Exi t()
    Else
    e.Cancel = True
    End If
    End Sub

    Thanks,

    Onur Güzel

    Comment

    • Armin Zingler

      #3
      Re: Confirm Exit in a Mdi form?

      "iDesmet" <idesmet.work@g mail.comschrieb
      Hallo,
      >
      I have a Mdi form in which I show a MessageBox if the user tries to
      close it. If the user clicks YES, then the form closes; if it clicks
      NO then it aborts.
      >
      I added the following lines in my form Closing event:
      >
      If MessageBox.Show ("Are you sure do you want to exit?", gsAppName,
      MessageBoxButto ns.YesNo, MessageBoxIcon. Question,
      MessageBoxDefau ltButton.Button 2) = Windows.Forms.D ialogResult.Yes
      Then Me.Close()
      End If
      >
      But it doesn't work. So I was wondering if someone is so kind to
      point me to the error.

      If MessageBox.Show ("Are you sure do you want to exit?", gsAppName, _
      MessageBoxButto ns.YesNo, MessageBoxIcon. Question, _
      MessageBoxDefau ltButton.Button 2) = Windows.Forms.D ialogResult.No
      Then
      e.cancel = True
      End If

      Note: DialogResult.Ye s changed to DialogResult.No .

      You don't have to (or must not) call Me.Close because it must have been
      called before already; otherwise the FormClosing event would not have been
      fired.


      Armin

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: Confirm Exit in a Mdi form?

        David,

        Just from my memory.

        DirectCast(me.M DIParent,TheMai nForm).Close()

        Would do the trick

        (I am not so busy with all the kind of tricks in VBNet for VB6 users, so
        maybe it can be done with less code)

        Cor

        "iDesmet" <idesmet.work@g mail.comschreef in bericht
        news:17d12d7f-7bf8-4ad1-9182-782ae22c97eb@d4 5g2000hsc.googl egroups.com...
        Hallo,
        >
        I have a Mdi form in which I show a MessageBox if the user tries to
        close it. If the user clicks YES, then the form closes; if it clicks
        NO then it aborts.
        >
        I added the following lines in my form Closing event:
        >
        If MessageBox.Show ("Are you sure do you want to exit?", gsAppName,
        MessageBoxButto ns.YesNo, MessageBoxIcon. Question,
        MessageBoxDefau ltButton.Button 2) = Windows.Forms.D ialogResult.Yes Then
        Me.Close()
        End If
        >
        But it doesn't work. So I was wondering if someone is so kind to point
        me to the error.
        >
        I'm using VB.NET
        >
        Thanks in advance.
        >
        PS My apologies for my bad english.
        >
        Best Regards,
        David Desmet

        Comment

        • iDesmet

          #5
          Re: Confirm Exit in a Mdi form?

          Thank you all for the kind help and fast reply... this has helped me
          very much.

          I appreciate your time.

          Thanks,
          David Desmet

          Comment

          Working...