• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 806
  • Last Modified:

vb.net form minimize to tray

I have a vb.net 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()
        [CODE]


        [/CODE]

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

        'has to be the last line
        mainForm.ShowDialog()
    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
            Me.Hide()
        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.Show()
            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
-Smit.
0
ullfindsmit
Asked:
ullfindsmit
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Instead of:

    mainForm.ShowDialog()

use...

    Application.Run(mainForm)
0
 
ullfindsmitAuthor Commented:
awesome... can you explain why showDialog wont work though ??

-Smit.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Because ShowDialog() holds until the form is either closed or HIDDEN.

When your code hits this line:

    Me.Hide()

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now