By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,741 Members | 2,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,741 IT Pros & Developers. It's quick & easy.

Close Event ?

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
> 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
Nov 20 '05 #2

P: n/a
* "Stan Sainte-Rose" <st**@cyber972.com> scripsit:
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...

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
> 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
Nov 20 '05 #4

P: n/a
* "Blumidoo" <no****@nottelling.com> scripsit:
I /hate/ applications which show a messagebox before exitting...


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.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #5

P: n/a
> > 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
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.