NotifyIcon Confusion

L

LineSupport

Hello,

I am a little confused over the behavior of a form with a NotifyIcon.
The property ShowInTasbar of the form is set to false. The NotifyIcon
does have an Icon set.

When I minimize the form, the Icon appears in the system tray as
expected. But, when I click on the icon the first time, the form
restores to a small window just above the Taskbar as if it had been
minimized.

A second mouse click on the Icon restores the form in its full glory.

The code below is complete. I created this simple test application
just to test the NotifyIcon behavior.

The behavior I would like is as follows.
1. Not visible in the Taskbar
2. Minimize hides the form.
3. An attempt to Close the form without password hides the form.
4. Click on the Icon restores the Form to previous location.

Public Class formTest

Private Sub formTest_FormClosing(ByVal sender As Object, ByVal e
As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If TextBox1.Text = "PASS" Then
e.Cancel = False
Else
e.Cancel = True
Me.WindowState = FormWindowState.Minimized
End If
End Sub

Private Sub formTest_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
NotifyIconX.Text = "Just_A_Icon :" & vbCr & "Double Click to
Activate."
End Sub

Private Sub formTest_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
Hide()
End If
If Me.WindowState = FormWindowState.Maximized Then
Debug.Print("Showing")
Me.WindowState = FormWindowState.Normal
Show()
End If
End Sub

Private Sub NotifyIconX_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NotifyIconX.Click
Me.WindowState = FormWindowState.Normal
Show()
End Sub

End Class


Thanks,
 
B

Brian

Hello,

I am a little confused over the behavior of a form with a NotifyIcon.
The property ShowInTasbar of the form is set to false. The NotifyIcon
does have an Icon set.

When I minimize the form, the Icon appears in the system tray as
expected. But, when I click on the icon the first time, the form
restores to a small window just above the Taskbar as if it had been
minimized.

A second mouse click on the Icon restores the form in its full glory.

The code below is complete. I created this simple test application
just to test the NotifyIcon behavior.

The behavior I would like is as follows.
1. Not visible in the Taskbar
2. Minimize hides the form.
3. An attempt to Close the form without password hides the form.
4. Click on the Icon restores the Form to previous location.

Public Class formTest

    Private Sub formTest_FormClosing(ByVal sender As Object, ByVal e
As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If TextBox1.Text = "PASS" Then
            e.Cancel = False
        Else
            e.Cancel = True
            Me.WindowState = FormWindowState.Minimized
        End If
    End Sub

    Private Sub formTest_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
        NotifyIconX.Text = "Just_A_Icon :" & vbCr & "Double Click to
Activate."
    End Sub

    Private Sub formTest_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            Hide()
        End If
        If Me.WindowState = FormWindowState.Maximized Then
            Debug.Print("Showing")
            Me.WindowState = FormWindowState.Normal
            Show()
        End If
    End Sub

    Private Sub NotifyIconX_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NotifyIconX.Click
        Me.WindowState = FormWindowState.Normal
        Show()
    End Sub

End Class

Thanks,

<Solved> Ok, found something that works. Don't know why. Just does.

In NotifyIconX_Click, I tried to set the Forms position to a known
position along with setting the form width and height, but got the
same results.

Private Sub NotifyIconX_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NotifyIconX.Click
Me.Left = 10
Me.Top = 10
Me.Width = 300
Me.Height = 300
Show()
End Sub

I tried storing the form location and size just before mimimizing,
which when checked in the debugger, stored the values just fine. But
when assigned to the form loaction and size in the NotifyIcon click
event, the value would not actually be reflected if you looked at the
Me.Width, Height etc, etc, etc.

Looks like you can not reliably change form attributes for the form
from the NotifyIcon events.

But, I made the following modifications.

Private Sub NotifyIconX_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles NotifyIconX.Click
Show()
Restore()
End Sub

Sub Restore()
Me.WindowState = FormWindowState.Normal
End Sub

This seems to be working fine. Hope this helps anyone else who was
have this same issue.

If anyone knows why this works, I would love to hear from you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top