Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Detect CancelButton

Options
  • 28-11-2008 5: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 Posts: 68,317 ✭✭✭✭seamus


    What language? What kind of form?


  • Registered Users 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,689 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