wallace740
wallace740

Reputation: 1380

Missing form after Minimize - Windows form application

I try to minimize my form to system tray but when I do, the form disappears and the notification icon doesnt work :(

What am I doing wrong?

Private Sub Form1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    If Me.WindowState = FormWindowState.Minimized Then
        Me.Visible = False
        NotifyIcon1.Visible = True
    End If
End Sub


Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick, NotifyIcon1.BalloonTipClicked
    Me.WindowState = FormWindowState.Normal
    Me.Visible = True
    NotifyIcon1.Visible = False
End Sub

I initialize NotificationIcon text, balloon tip and other stuff in the aspx page

Upvotes: 1

Views: 2460

Answers (2)

wallace740
wallace740

Reputation: 1380

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    NotifyIcon1.Icon = Me.Icon
End Sub

In the tutorial it was not telling me to include Icon in the Form Load, that was the reason.

Problem solved! :)

Upvotes: 0

user472157
user472157

Reputation: 146

That's in C# but the idea should be obvious :)

private void Form1_SizeChanged(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Minimized)
    {
        notifyIcon1.Visible = true;
        this.ShowInTaskbar = false;
        this.Hide();
    }
    else
    {
        notifyIcon1.Visible = false;
    }
}

void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
    notifyIcon1.Visible = false;
    this.ShowInTaskbar = true;
    this.Show();
    this.WindowState = FormWindowState.Normal;
}

Upvotes: 1

Related Questions