How to tell apart a form closing a result of user clicking the X button vs another event?

Answered
0
0

Let’s say I have a form.  It has an “Exit” button with a click event that calls this.Close().  When the button is clicked, a FormClosing event is fired.

In this event, I want to be able to differentiate between the Exit button being clicked and user clicking the X button on the top right?  I examined the sender argument and its always the form regardless of what I clicked.  Similarly e.CloseReason is always UserClosing.

So short of having a variable that tracks this, is there a way to differentiate between the regular button and an X button?

 

P.S.  I am on WiseJ 2.2.x

 

  • You must to post comments
Best Answer
1
0

Hi Matthew,

actually my previous reply was wrong as I mixed ClientEvent with ClickEvent and misunderstood your question.

Seeing the sender always the form is because it´s always the form firing that event (.NET convention).

But, you can use the DialogResult property of the button. Clicking on the “X” to close the window always results in DialogResult = None.
If you assign a DialogResult value to the button property, you´ll see it in the FormClosing event.

Please find a simple sample attached that shows how it works.

Best regards
Frank

Attachment
  • You must to post comments
0
0

Hi Matthew,

this.close() on the client (browser) is always considered a user event so it’s UserClosing.
Maybe you can add some custom property/flag that you trigger when your user clicks on the Exit button?

Best regards
Frank

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.