Dectecting close (X) click

  • Thread starter Thread starter Nick Zdunic
  • Start date Start date
N

Nick Zdunic

Hello.

I may have missed something simple here but I want to know that when a form is closed whether it was closed when the X is clicked.

How is this achieved?
 
Hello.

I may have missed something simple here but I want to know that when a form is closed whether it was closed when the X is clicked.

How is this achieved?

What I do is when the user selects a "close" button (not the X button), I
set a boolean variable. That way if it is set, I know they did not click
the X but instead clicked the close button. If they clicked the X, the
boolean is not set.

In the form_closing event:

Private bCloseButtonClicked As Boolean

Public Sub Form_Closing(...)
If bCloseButtonClicked then
MsgBox("Closing from close button")
Else
MsgBox("Closing from clicking the X button")
End IF
End Sub

Public Sub Close_Button_Click(...)
bCloseButtonClicked = True
End Sub


This is a workaround but it can work reliably. You may also be able to
intecept the windows messages in the WndProc override and determine it that
way.

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
 
Hi Nick,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top