Solved

How to minimize my program to the system tray?

Posted on 2007-11-24
9
1,466 Views
Last Modified: 2013-11-26
Hello,

I need to get my application to minimise to the system tray instead of the system bar (I don't know what you call that). I have tried searching but the codes is either obselute or either do not work on a VB.NET form only on VB form.

I hope its very easy to implement just to go to system tray and back up upon double (or right if possible) clicking it. It would be better if it had the balloon notification thingy when a event occurs (with timer) but I will probably ask a question for that next time.
0
Comment
Question by:Sharalynn
9 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20342375
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 20342382
Very good link that can solve your need.
http://www.codeproject.com/system/MinimizedAnyWindowToTray.asp
0
 

Author Comment

by:Sharalynn
ID: 20342574
I don't understand the stuff in the first link (too many inner workings stuff I do not know lol..), and the second link does not seem to apply to the coding of the program itself. I am looking for something like http://support.microsoft.com/kb/q176085/ so i can just plug in and play but for vb.net 2005
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20342616
If you don't understand the code from my link, I have to assume that you don't have enough knowledge of vb.net coding at all?:....

you only need to look at the visual basic code section.

anyhow, let me explain the important lines.

Imports System
Imports System.Drawing
Imports System.Windows.Forms

Public NotInheritable Class Form1
    Inherits System.Windows.Forms.Form


    'the next 3 lines define the context menu and the notify icon reference variables.
    Private contextMenu1 As System.Windows.Forms.ContextMenu
    Friend WithEvents menuItem1 As System.Windows.Forms.MenuItem
    Friend WithEvents notifyIcon1 As System.Windows.Forms.NotifyIcon


    Private components As System.ComponentModel.IContainer

    <System.STAThread()> _
    Public Shared Sub Main()
        System.Windows.Forms.Application.Run(New Form1)
    End Sub 'Main

    'this is the constructor of the form's class
    Public Sub New()

        Me.components = New System.ComponentModel.Container
        'creating the context menu

        Me.contextMenu1 = New System.Windows.Forms.ContextMenu
        Me.menuItem1 = New System.Windows.Forms.MenuItem

        ' Initialize contextMenu1
        Me.contextMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() _
                            {Me.menuItem1})

        ' Initialize menuItem1
        Me.menuItem1.Index = 0
        Me.menuItem1.Text = "E&xit"

        ' Set up how the form should be displayed.
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Text = "Notify Icon Example"

        ' Create the NotifyIcon.
        Me.notifyIcon1 = New System.Windows.Forms.NotifyIcon(Me.components)

        ' The Icon property sets the icon that will appear
        ' in the systray for this application.
        notifyIcon1.Icon = New Icon("appicon.ico")

        ' The ContextMenu property sets the menu that will
        ' appear when the systray icon is right clicked.
        notifyIcon1.ContextMenu = Me.contextMenu1

        ' The Text property sets the text that will be displayed,
        ' in a tooltip, when the mouse hovers over the systray icon.
        notifyIcon1.Text = "Form1 (NotifyIcon example)"
        notifyIcon1.Visible = True
    End Sub 'New
   
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        ' Clean up any components being used.
        If disposing Then
            If (components IsNot Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub 'Dispose


    ' this is the event handler for double clicking the notify icon
    Private Sub notifyIcon1_DoubleClick(Sender as object, e as EventArgs) handles notifyIcon1.DoubleClick
        ' Show the form when the user double clicks on the notify icon.

        ' Set the WindowState to normal if the form is minimized.
        if (me.WindowState = FormWindowState.Minimized) then _
            me.WindowState = FormWindowState.Normal

        ' Activate the form.
        me.Activate()
    end sub

    ' handling the menu click to close the form
    Private Sub menuItem1_Click(Sender as object, e as EventArgs) handles menuItem1.Click
        ' Close the form, which closes the application.
        me.Close()
    end sub

End Class 'Form1







0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:Sharalynn
ID: 20343154
Error      1      'components' is already declared as 'Private Dim components As System.ComponentModel.IContainer' in this class.      C:\Alerter\Alerter\Form1.vb      15      13      Alerter
Warning      2      'Public Sub New()' in designer-generated type 'Alerter.Form1' should call InitializeComponent method.      C:\Alerter\Alerter\Form1.vb      23      16      Alerter


After commenting out the first error and changed New to initializecomponent I find that the method name already exists in Form1.Designer.vb:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    ''Form overrides dispose to clean up the component list.
    '<System.Diagnostics.DebuggerNonUserCode()> _
    'Protected Overrides Sub Dispose(ByVal disposing As Boolean)
    '    Try
    '        If disposing AndAlso components IsNot Nothing Then
    '            components.Dispose()
    '        End If
    '    Finally
    '        MyBase.Dispose(disposing)
    '    End Try
    'End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(284, 264)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub
End Class
0
 

Author Comment

by:Sharalynn
ID: 20345433
Solved it with solution here: http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_22564430.html

But if anyone has more ideas for the tray part, feel free to post!
0
 

Author Comment

by:Sharalynn
ID: 20345434
Or if the solution (2 methods) has any flaw please let me know too, thanks.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 20591195
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

23 Experts available now in Live!

Get 1:1 Help Now