Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6540049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:55:54+00:00 2026-05-25T10:55:54+00:00

I have an application which is in system tray. I want to make it

  • 0

I have an application which is in system tray. I want to make it visible when the user clicks on the notifyIcon, if it’s not visible already. If it is already visible it should be hidden. Also when the user clicks anywhere else except on the form the form should hide (if it’s visible).

My code looks like this:

protected override void OnDeactivated(EventArgs e)
{
    showForm(false);
}

public void showForm(bool show)
{
    if(show)
    {
        Show();
        Activate();
        WindowState = FormWindowState.Normal;
    }
    else
    {
        Hide();
        WindowState = FormWindowState.Minimized;
    }
}

private void notifyIcon1_MouseClicked(object sender, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Left)
    {
        if (WindowState != FormWindowState.Normal)
        {
            showForm(true);
        }
    }
}

The problem with the code is that onDeactivated gets called before the click call, which hides the form and notifyIcon1_MouseClicked than just re-shows it. If I could detect if the focus was lost due to a click on notifyIcon or elsewhere it would solve the problem.

I’ve done my research and found a similar thread, but the solution just detected if the mouse position is over the tray when onDeactivated gets called: C# toggle window by clicking NotifyIcon (taskbar icon)

UPDATE:
The solution I posted only detects if the user’s mouse is over the tray icons in the taskbar, so if you click on any other tray the onDeactivated event won’t get fired.
I want to get the same functionality as the system volume app.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:55:55+00:00Added an answer on May 25, 2026 at 10:55 am

    Simply keep track of the time when the window was last hidden. And ignore the mouse click if that happened recently. Like this:

    int lastDeactivateTick;
    bool lastDeactivateValid;
    
    protected override void OnDeactivate(EventArgs e) {
        base.OnDeactivate(e);
        lastDeactivateTick = Environment.TickCount;
        lastDeactivateValid = true;
        this.Hide();
    }
    
    private void notifyIcon1_MouseClick(object sender, MouseEventArgs e) {
        if (lastDeactivateValid && Environment.TickCount - lastDeactivateTick < 1000) return;
        this.Show();
        this.Activate();
    }
    

    Clicking the icon repeatedly now reliably toggles the window visibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows form application which exit to a system tray Notifyicon and
I have a system tray application which gets installed and starts running from a
I have a created a tray application. User can tick the file extensions which
I have an application which resides in the system tray, and instead of the
I have an application in java swing which runs in the system tray most
I have an application in which we use a hand-made build system.The reason for
I have a MFC dialog based application in which I use ::system() function to
I have a current system which is build as a Windows Application, and does
I have following requirement, I have C#/.Net console application, which refers to 'System.Data.Sqlite.dll' 'System.Data.Sqlite.dll'
I have an application which doesn't use ARC. Now I want to integrate twitter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.