Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Detect CancelButton

  • 28-11-2008 05:30PM
    #1
    Closed Accounts Posts: 2,268 ✭✭✭


    If the CancelButton (top right X ) is clicked on a form is there any way to detect the action?

    Veeeeeery Good Question Seamus

    In VB.net if a forms CancelButton is clicked can this interaction be detected. Alternatively is it possible in VB.net to determine which forms are currently visible. In aforms collection which can hold only 1 copy of each form at a time.


    The formis currently initialised as show dialog but that is negotiable.

    MM


Comments

  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    What language? What kind of form?


  • Registered Users, Registered Users 2 Posts: 177 ✭✭mercuroman


    I presume you are talking about using winforms in vb.net. If you are using a dialog box - ie. Open File Dialog - then you can tell what the user has clicked by doing the following:
    Dim dr as DialogResult
    dr = OpenFileDialog.ShowDialog()
    if (dr = DialogResult.OK) then (user has hit ok)
    else if (dr = DialogResult.Cancel) then (user has hit cancel)

    Is this what you are looking for?


  • Moderators, Society & Culture Moderators Posts: 9,688 Mod ✭✭✭✭stevenmu


    I think he means a standard form (window).

    If so the easy way is to handle the form_closing event
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            MessageBox.Show("Goodbye")
    End Sub
    

    and if you need to override it
    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            MessageBox.Show("Goodbye")
            e.Cancel = true
    End Sub
    

    It's not technically catching the x button, it'll also fire if the form is closed other ways too.


  • Closed Accounts Posts: 2,268 ✭✭✭mountainyman


    StephenMu that's amazing. That really did the trick.


Advertisement