• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 569
  • Last Modified:

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
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:
tray mousedown
tray mouseup
tray mouseclick

Open in new window

1 Solution
DFPITCAuthor Commented:
I've ended up setting a global var called etime (event time)
When the deactivate event fires, or the tray icon click event fires it sets the etime to the current time.
On the deactivate event and the tray icon click event, I compare etime to now to make sure at least 100ms has passed.
This ensures that the form doesn't hide and show itself too close together (eg: when both events fired)

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now