Setting Form to Hide using Deactivate for VB.Net app

Posted on 2014-07-14
Last Modified: 2014-07-14
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

Question by:DFPITC
    1 Comment

    Accepted Solution

    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)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now