Okay, here's the senario:

I want the form to hide when I click on the minimize button, then the notify icon will show up on the system tray. I have this piece of code:

(ntfLibSMS is the name of my notify icon)

Private Sub LibSMS_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Try
            If Me.WindowState = FormWindowState.Minimized Then
                Me.WindowState = FormWindowState.Minimized
                ntfLibSMS.Visible = True
                Me.Hide()
            End If

        Catch ex As Exception
            ErrorCodes.ErrorMessages("LibSMS_Resize()", ex.Message)
        End Try
    End Sub

It doesn't work. T_T The form hides, but the notify-icon didn't appear... Any suggestions? Do you have any idea how I could fix this?

Okay, here's the senario:

I want the form to hide when I click on the minimize button, then the notify icon will show up on the system tray. I have this piece of code:

(ntfLibSMS is the name of my notify icon)

Private Sub LibSMS_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Try
            If Me.WindowState = FormWindowState.Minimized Then
                Me.WindowState = FormWindowState.Minimized
                ntfLibSMS.Visible = True
                Me.Hide()
            End If

        Catch ex As Exception
            ErrorCodes.ErrorMessages("LibSMS_Resize()", ex.Message)
        End Try
    End Sub

It doesn't work. T_T The form hides, but the notify-icon didn't appear... Any suggestions? Do you have any idea how I could fix this?

Hey

i suggest inserting a timer.
lets pretend that that the form is "Form" an the notify icon is "systrayico", the timer is "timer1"

enable the timer, make the notifyicon not visible, set the timer to an appropriate interval (eg 10ms) then insert this code

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Me.WindowState = FormWindowState.Minimized Then
            systrayico.Visible = True
        ElseIf Me.WindowState = FormWindowState.Normal Then
            systrayico.Visible = False
        ElseIf Me.WindowState = FormWindowState.Maximized Then
            systrayico.Visible = False
        End If
    End Sub

also, i had problems, as it wouldnt work for me without having already applied the icon

Edited 6 Years Ago by butler1233: wrong code

See if this helps by using the Deactivate event.

Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate
        '// your code here to show the notify icon.
    End Sub

To hide the icon, use the Activated event.

Edited 6 Years Ago by codeorder: n/a

Hey

i suggest inserting a timer.
lets pretend that that the form is "Form" an the notify icon is "systrayico", the timer is "timer1"

enable the timer, make the notifyicon not visible, set the timer to an appropriate interval (eg 10ms) then insert this code

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Me.WindowState = FormWindowState.Minimized Then
            systrayico.Visible = True
        ElseIf Me.WindowState = FormWindowState.Normal Then
            systrayico.Visible = False
        ElseIf Me.WindowState = FormWindowState.Maximized Then
            systrayico.Visible = False
        End If
    End Sub

also, i had problems, as it wouldnt work for me without having already applied the icon

I also found it odd. I searched the whole internet for a working code, all of them seem really simple and people were like "thank you! this works great!" but when I tried it, there was nothing! Although I did found a working copy, only that it was version 2003, and it was not as automated like this one. It had a really long code which gave me a nosebleed.

I am yet to try this, but thank you for telling me. :D

See if this helps by using the Deactivate event.

Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Deactivate
        '// your code here to show the notify icon.
    End Sub

To hide the icon, use the Activated event.

I'll try this as well.
Thank you for the idea. :D

Jus guessing if the problem is in the task bar properties to hide the inactive icons.

Had you already tried to set it not to hide them?

This article has been dead for over six months. Start a new discussion instead.