Tommy
Tommy

Reputation: 21

NotifyIcon disappears on Me.Hide?

I'm currently coding a multi-form project that requires a NotifyIcon. The first form is the Login form which then opens a 'logging-in' form and then finally another form (they're all opened using FormName.ShowDialog() and they hide themself before opening the next form).

Login Form -> Logging In Form -> Final Form.

When the final form is opened, the NotifyIcon's visible property is set to true and it appears in the tasktray like normal. But when I use Me.Hide on the final form, the NotifyIcon disappears with the form.

Any ideas about what is going on? The program still runs in the background despite no forms are visible (which is how it's intended to be) but without a NotifyIcon, there's no way of making the forms appear again.

EDIT - If it helps, the Logging In Form is opened in another thread but using a delegate.

Upvotes: 1

Views: 740

Answers (3)

Troy Mitchel
Troy Mitchel

Reputation: 1810

You can hide form in the Form_Shown event.

Private Sub Form1_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
    Me.Hide
End Sub

Upvotes: 0

Tommy
Tommy

Reputation: 21

I found an alternative solution to the problem. Instead of using Me.Hide, I used: Me.Opacity = 0 which did not cause the NotifyIcon to disappear (and on the NotifyIcon it sets Me.Opacity to 100 when clicked on).

Thanks for trying to help guys.

Upvotes: 1

Jalal Said
Jalal Said

Reputation: 16162

You should set "initialize" the notification icon on the main form "the form that will always appears after all forms dialog finished". If the problem still occurred "it should not!" then try to use Me.VisibleChanged event so whenever the form visibility changed to visible, implicitly call notificationIcon.Visible = true, btw are you setting the notification icon visible to false elsewhere?

Upvotes: 0

Related Questions