Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NotifyIcon Show Desktop Button Form Not Displaying / Showing

Status
Not open for further replies.

bont

Programmer
Joined
Sep 7, 2000
Messages
200
Location
US
Hi All

I searched high and low for a solution to my problem, and didn't really find it, until I found a semi-unrelated article talking about vb.net threading problems and form visibility. Since I had already tried the focus, and refresh methods of the form, I tried the activate method of the form.

This solves a problem when a user may hit the "Show Desktop" button of the windows OS. As you may recall, this button minimizes all windows. Although I tried to reset the window state to normal, the window still would not appear, except when another window would cause it to.

This code demo hides the window (the hide/show methods don't work for this purpose, consistently), so the visible attribute is used. You must make sure the window state is always normal, when trying to show.

Code:
' Declaration
Private dICON As New Icon(Application.StartupPath & "\Convert 1.ico")

' On Form Load
' F.Y.I. I open Form using Sub Main
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Icon = dICON
    NotifyIcon1.Icon = dICON
    Me.Visible = False
    Me.Update()
End Sub

' On Click of Notify Icon 1, located on form
Private Sub NotifyIcon1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDown
    ' Show the form
    Me.Visible = Not Me.Visible
    ' Just in case user has hit minimize all
    Me.WindowState = FormWindowState.Normal
    ' This is very important.  Must be called due to threading issue!!!
    Me.Activate()
End Sub

F.Y.I. If you want the user to use the minimize button an retract back to the system tray, you will have to do additional code. Please let me know if you find a good way to do it, I might be looking at that soon.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top