Link to home
Start Free TrialLog in
Avatar of DFPITC
DFPITCFlag for Australia

asked on

Setting Form to Hide using Deactivate for VB.Net app

I am developing a form with a tray icon.

I want it so you can click on the tray icon to show the form or hide the form.
I also want it so if you click away from the form (eg: the desktop) it also hides the form.

Now, using the form event "deactivate" I can put a Me.Hide() to hide the form.

The tray icon click event has code like the following:
if Me.Visible Then
	Me.Hide()
Else
	Me.Show()
	Me.Activate()
End If

Open in new window

The problem I have is, when the form is visible, and I click the tray icon, the deactivate event fires, which hides the form, THEN the form click event fires which reactivates it.

How to I tell the deactivate event not to run me.Hide() if the tray icon is clicked. (preferrable)
Alternatively, how do I tell the tray icon click event not to run the code if deactivate just hid the form
(i'd rather not use timers)

When the form is active, looking at the event order (with a debug window) the event chain is:
deactivate
tray mousedown
tray mouseup
tray mouseclick

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of DFPITC
DFPITC
Flag of Australia 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