Results 1 to 2 of 2

Thread: problems with opening/hiding forms

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2002
    Posts
    67

    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

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Oct 2002
    Posts
    67
    Actually I have located an example of a MUCH better way of doing this. The following code was posted on Planet Source Code and authored by Jose Fuentes. Now, the only problem i have, is hiding the form on formload.. me.hide() does not work.


    http://www.planetsourcecode.com/vb/s...=434&lngWId=10




    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Timer1.Enabled = False
    End Sub

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
    Me.Hide()
    End Sub

    Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
    Me.Show()
    End Sub

    Private T As Boolean
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    If T = False Then
    NotifyIcon1.Icon = New System.Drawing.Icon(Application.StartupPath & "\CFS4.ico")
    T = True
    Else
    NotifyIcon1.Icon = New System.Drawing.Icon(Application.StartupPath & "\CFS3.ico")
    T = False
    End If
    Timer1.Enabled = False
    Timer1.Enabled = True
    End Sub
    Private Sub MyForm_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
    e.Cancel = "true"
    Me.Hide()
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width