tags:

views:

301

answers:

1

I'm currently using VB.Net 2008.
The project has the "make single instance application" checkbox checked.

The application works by hiding the form when the form is minimized.

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

When the appropriate menu item is pressed within the notifyicon the form should show itself again.

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

This works fine until the user tries to open the same application while the form is minimized. When this occurs the application will block a new instance of the application the user was trying to open as expected, however when the user then goes to show the form from the notifyicon's menu it will have seemed to open (it shows the form in the taskbar) but no window is shown.

At this point the window can be maximized and works as intended but by using the restore button the window will not be drawn but will still be shown in the taskbar.

If any help can be given on how to restore the form correctly from being hidden it would be most appreciated.

Thanks in advance

A: 

Just a couple of suggestions...

Instead of using Hide() and Show(), could you use the ShowInTaskbar property of the form instead?

Set it to false where you use Hide() and true where you currently use Show(), and see if that makes any difference.

Or perhaps set the WindowState to Normal before calling Show().

Andy
First and foremost thank you for your response.To clarify the functionality works as intended in normal operation. That is until someone tries to start a new instance of the application while the current application is minimized.I'll try out your suggestion with the showintaskbar property, that sounds promising.
Keith Pike
Just tested the showintaskbar property. It works however a different error occurs. When the form is minimized and the user tries to initiate a new instance of the application the form reappears. Also when the form is then minimized, the title bar shows in the lower left corner of the screen, but only when the window that holds the .exe that tried to start the application is not minimized. Once that window is minimized the form works as normal. Once again thanks for the response.
Keith Pike