[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1481
  • Last Modified:

How to minimize my program to the system tray?

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
Sharalynn
Asked:
Sharalynn
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
0
 
Shanmuga SundaramDirector of Software EngineeringCommented:
Very good link that can solve your need.
http://www.codeproject.com/system/MinimizedAnyWindowToTray.asp
0
 
SharalynnAuthor Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
SharalynnAuthor Commented:
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
 
SharalynnAuthor Commented:
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
 
SharalynnAuthor Commented:
Or if the solution (2 methods) has any flaw please let me know too, thanks.
0
 
Computer101Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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