How add code to the close button (title bar)

I'd like to display a msgbox when the user clicks the close button (X) at the title bar.
An option to the user is to save data or not.

I tried to use the event .disposed, but the frame was already closed before the msgbox is shown. This will work, but it would be more 'fancy' if the form was still visible.

Is there any form event for the close button?

Thanks

[435 byte] By [Cobolman] at [2007-12-28]
# 1
I found that I could add an event to the form:

Private Sub frmDBView_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
MsgBox(...)
End Sub

Why is this event not shown in the IDE? (Where you find the other events .. click, onchange, etc...)

Cobolman at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Where are you looking for this specific event? This is the BaseClass event: you probably need the FormClosing (or FormClosed) event - unless there is some specific reason you need the baseclass Closing event. In which case, yes, you would have to handle (code) it manually.

SJWhiteley at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic Language...