Close Event ?

S

Stan Sainte-Rose

Hi,
Which event is called when the user click on the close window icon (X) ?
I want, when he clicks on this icon, to display a message before closing the
form.
If he replys by No, I don't want to close the form.

Thks for your help

Stan
 
B

Blumidoo

Hi,
Which event is called when the user click on the close window icon (X) ?
I want, when he clicks on this icon, to display a message before closing the
form.
If he replys by No, I don't want to close the form.

From the doc:

Form.Closing Event [Visual Basic]
Occurs when the form is closing.
[Visual Basic]
Public Event Closing As CancelEventHandler

The Closing event occurs as the form is being closed. When a form is closed,
all resources created within the object are released and the form is
disposed. If you cancel this event, the form remains opened. To cancel the
closure of a form, set the Cancel property of the CancelEventArgs passed to
your event handler to true.
When a form is displayed as a modal dialog box, clicking the Close button
(the button with an X at the upper-right corner of the form) causes the form
to be hidden and the DialogResult property to be set to DialogResult.Cancel.
You can override the value assigned to the DialogResult property when the
user clicks the Close button by setting the DialogResult property in an
event handler for the Closing event of the form.
Note When the Close method is called on a Form displayed as a modeless
window, you cannot call the Show method to make the form visible, because
the form's resources have already been released. To hide a form and then
make it visible, use the Control.Hide method.
CAUTION The Form.Closed and Form.Closing events are not raised when the
Application.Exit method is called to exit your application. If you have
validation code in either of these events that must be executed, you should
call the Form.Close method for each open form individually before calling
the Exit method.
If the form is an MDI parent form, the Closing events of all MDI child forms
are raised before the MDI parent form's Closing event is raised. In
addition, the Closed events of all MDI child forms are raised before the
Closed event of the MDI parent form is raised

sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
************************************
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
 
H

Herfried K. Wagner [MVP]

* "Stan Sainte-Rose said:
Which event is called when the user click on the close window icon (X) ?
I want, when he clicks on this icon, to display a message before closing the
form.
If he replys by No, I don't want to close the form.

\\\
Private Sub Form1_Closing( _
ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs _
) Handles MyBase.Closing
If ... Then
e.Cancel = True
End If
End Sub
///

I /hate/ applications which show a messagebox before exitting...
 
B

Blumidoo

I /hate/ applications which show a messagebox before exitting...

And I hate applications that close without asking to save my work _first_...

sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
************************************
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
 
H

Herfried K. Wagner [MVP]

* "Blumidoo said:
And I hate applications that close without asking to save my work _first_...

I would at least include an option which allows the user to turn the
messagebox off.
 
B

Blumidoo

And I hate applications that close without asking to save my work
_first_...
I would at least include an option which allows the user to turn the
messagebox off.

Good point, good practice. :)

sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
************************************
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top