Solved

How to minimize my program to the system tray?

Posted on 2007-11-24
9
1,471 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 143

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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
LVL 143

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
 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

830 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