Link to home
Start Free TrialLog in
Avatar of Jigit
JigitFlag for Israel

asked on

How to discover the originator control of form closing?

Hello, Experts!

I'd like to know what control caused the form to be closed. For eaxample, was it the "X", or some else button on hte form.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gregasm
gregasm

In the Form1_Closing event,

Set a break point somewhere in the event handler.

Then in the immediates window, examine the sender parameter. (sender as Object).

This is the sender who raised the close event.

Try this:

if typeof(sender) is button then

elseif typeof(sender) is textbox then


elseif typeof(sender) is label then



end if


etc...
gregasm,

It didn't matter if I closed the form via the X button, a button using Me.Close, or from the Task Manager.  The sender was always Form1.

~IM
Avatar of Jigit

ASKER

Idle_Mind, thanks for your answer. It does work. And you are absolutely right - the sender is always the Form.