Solved

How to minimize my program to the system tray?

Posted on 2007-11-24
9
1,472 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 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