problems with opening/hiding forms
I really hope someone can help. The following is a problem thats been driving me nuts the past couple of days.
The following is what I want:
A simple form that has a notifyicon(tray icon), and some other controls on it. When the program is executed the form is loaded as minimized and not displayed in taskbar. Clicking on the notifyicon should make the form visible. Closing the form should leave the notifyicon in the tray, but once again hide the form from view.
This is what i've done:
Placed a notidyicon on the main form. load the form as minimized and not in the taskbar. when the notifyicon is clicked on I call a new instance of the form(dim myform as new forms1). I then display the form. Displaying the form brings a second icon to the tray, so i also dispose of the old icon, as to not cause doubles. I can then close the form, and cancle the close and have it hide instead of close. I click on the icon again and the same thing happens. problem: if the form is open, and i click the icon again another for comes up, and another and another, each time i click on it.
There has GOT to be a better way to do this, than to be disposing fo the notifyicon over and over. But when i make the program bring the forum status to normal instead of instanizing another form1 class, it doesnt work at all...
Help!
heres the code
Private Sub NotifyIcon1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDown
Dim myform As New Form1()
Me.WindowState = FormWindowState.Normal
myform.Show()
NotifyIcon1.Container.Dispose()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub MyForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
e.Cancel = "true"
Me.WindowState = FormWindowState.Minimized
End Sub