X-Button

R

riVn

(I allready used the search function of the dotnetboard, haven't seen
any post about it)

So, my problem is this one:

I wana have a msgbox when I click the normal X-button on the
right-top-corner of a normal
win form.

The msgbox would be like "Do you realy want to quit the app?" ... with
a yes and no button ...

I've allready some "Exit" or "Quit" buttons, but my problem is, I
don't know how to access this
stupid X-button. ( I know me.closing and me.closed, but I can't use it
in this case)

Sorry for my english ... and thx for help
 
C

CJ Taylor

Why can't you use Closing?


riVn said:
(I allready used the search function of the dotnetboard, haven't seen
any post about it)

So, my problem is this one:

I wana have a msgbox when I click the normal X-button on the
right-top-corner of a normal
win form.

The msgbox would be like "Do you realy want to quit the app?" ... with
a yes and no button ...

I've allready some "Exit" or "Quit" buttons, but my problem is, I
don't know how to access this
stupid X-button. ( I know me.closing and me.closed, but I can't use it
in this case)

Sorry for my english ... and thx for help
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed)-spam.invalid (riVn) scripsit:
(I allready used the search function of the dotnetboard, haven't seen
any post about it)

So, my problem is this one:

I wana have a msgbox when I click the normal X-button on the
right-top-corner of a normal
win form.

The msgbox would be like "Do you realy want to quit the app?" ... with
a yes and no button ...

I've allready some "Exit" or "Quit" buttons, but my problem is, I
don't know how to access this
stupid X-button. ( I know me.closing and me.closed, but I can't use it
in this case)

Add a handler to the form's 'Closing' event and set 'e.Cancel' to 'True'
there if you want to cancel the closing process.
 
S

Scott

The only other way I know to accomplish this is to handle the messages with
the WndProc. Add the following code to your form.


Private bCloseClicked As Boolean
Public Const SC_CLOSE As Integer = 61536
Public Const WM_SYSCOMMAND As Integer = 274

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_CLOSE Then
Dim res As DialogResult
res = MessageBox.Show("Do you wish to exit?", "Exit",
MessageBoxButtons.YesNo)
If res = DialogResult.Yes Then
' Do nothing
Else
' Exit sub to prevent base class
' from handling the message
Exit Sub
End If
End If
MyBase.WndProc(m)
End Sub


riVn said:
anybody out there who can help me?
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed)-spam.invalid (riVn) scripsit:
anybody out there who can help me?

Why not comment the replies and/or be more specific with the problem
description?
 

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