Solved form minimize to tray

Posted on 2006-05-09
Last Modified: 2008-01-09
I have a desktop app
I have a modMain.vb where I initialize my global variables before loading my form.

here is the code in modMain.vb
Module modMain

    Dim mainForm As New frmMain
    Dim WithEvents alertTicker As New Timer

    Sub main()


        alertTicker.Interval = 1000 * 60    '1000 => 1 Second / 60 => 60 seconds
        alertTicker.Enabled = True

        'has to be the last line
    End Sub

and here is teh code in my mainForm.vb file
    Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            notifyIcon.Visible = True
        End If
    End Sub

    Private Sub notifyIcon_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles notifyIcon.Click
        If Me.WindowState = FormWindowState.Minimized Then
            Me.WindowState = FormWindowState.Maximized
        End If
    End Sub

the problem is....
when i minimize my app.. it exits the program.... how do I avoid that ?

please advise
Question by:ullfindsmit
    LVL 85

    Accepted Solution

    Instead of:



    LVL 12

    Author Comment

    awesome... can you explain why showDialog wont work though ??

    LVL 85

    Expert Comment

    by:Mike Tomlinson
    Because ShowDialog() holds until the form is either closed or HIDDEN.

    When your code hits this line:


    Execution continues after your ShowDialog() call and subsequently runs into the end of your Sub Main()...thus ending your application.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now