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

  • Home
  • SEARCH
  • 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 4562278
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:11:35+00:00 2026-05-21T18:11:35+00:00

I am writting a program in vb.net that uses the systray and what I

  • 0

I am writting a program in vb.net that uses the systray and what I am trying to achieve is the following.

If the systray icon is clicked it should minimise/restore the form. (this I can do)
the bit I am stuck on is that if the form is ‘open’ and not focused I want it to get focus rather than minimise.

I can’t seem to find anything that does the test I need to see if the form is not in a minimised state and does not have focus.

Any suggestions welcome.

Thanks

  • 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-21T18:11:36+00:00Added an answer on May 21, 2026 at 6:11 pm

    Keep track of the form activation state by listening to the Activate and Deactivate events. One complication is that the form will be de-activated when you click the icon. Solve that by recording the time it happened. Like this:

    Public Class Form1
        Private IsActivated As Boolean
        Private DeActivation As DateTime
    
        Protected Overrides Sub OnActivated(e As System.EventArgs)
            IsActivated = True
            MyBase.OnActivated(e)
        End Sub
    
        Protected Overrides Sub OnDeactivate(e As System.EventArgs)
            IsActivated = False
            DeActivation = DateTime.Now
            MyBase.OnDeactivate(e)
        End Sub
    
        Private Sub NotifyIcon1_MouseClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseClick
            If Me.WindowState = FormWindowState.Minimized Then
                Me.WindowState = FormWindowState.Normal
            Else
                If IsActivated OrElse DateTime.Now - DeActivation < New TimeSpan(0, 0, 1) Then
                    Me.WindowState = FormWindowState.Minimized
                Else
                    Me.Activate()
                End If
            End If
    
        End Sub
    End Class
    

    This is otherwise a fairly unpleasant hack around having to set the form’s ShowInTaskbar property to False. It is possible to have a taskbar button and still keep the form invisible at startup. Check this answer for the approach.

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

Sidebar

Related Questions

I am writing a program that uses ADO.NET's SqlCommand to execute a number of
I have a program written in VB.NET which stops a service that uses file
I'm writing a program that uses java.net.URLDecoder.decode(String value, String encoding) . Apparently, this method
I'm writing a program that uses SetWindowRgn to make transparent holes in a window
I'm writing a C#.NET program which uses XmlSerializer to serialize and deserialize the project
I'm writing a c# application which uses automation to control another program. Naturally that
I'm writing a program in VB.NET that needs to get the path to the
I have an ASP.NET program that is writing date to an SQLExpress Database date
I'm writing a simple little program in VB.NET that has to play two sounds
I'm writing a program that sends an email out at a client's specific local

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.