Tray program refers to a kind of program: when the program is run, will be in the system tray area (also said to be the status area) to create this program icon, users can click on the menu icon appears to control the operation of the state. Pallet programs have many advantages, such as not taking up the screen, running in the background, easy to control and so on. So now more and more programs are made of the tray program. In vb.net, it is more convenient and simple to write a pallet program. This is because vb.net does not have its own class library, and the class library it uses is the common class Library ——. NET Framework SDK provided for all. NET Platform development languages in the. NET Framework. In this class library, for the writing of the tray program provides a specific class, call these classes can implement the program tray effect. Thus also get rid of its predecessor VB in dealing with such problems when the cumbersome. Here are two specific examples to learn how to use vb.net to write a pallet program.
The design and operating environment of this program
(1) Windows Service
(2) Net Framework SDK Official edition
The process of writing static tray program
The static pallet program refers to the tray program in which the icon in the system tray area is in the static state after the program is run. The dynamic pallet program is exactly the opposite, it refers to the system Tray area icon rendering animation effect of a class of tray program. Here is a discussion of how vb.net is implementing a static pallet program.
The. Net FrameWork SDK provides a component for writing a pallet program: the NotifyIcon component. The NotifyIcon component is a WinForm component, located in the namespace "System.Windows.Forms", in the VB.net program, as long as you create an instance of the NotifyIcon component, and the "Icon" for the NotifyIcon instance Property assignment, such a simple pallet program is complete. The following is the code for this simple pallet program (Form1.vb):
Public Class Form1
Inherits System.Windows.Forms.Form
#Region "code generated by the Windows forms Designer"
Public Sub New ()
MyBase.New ()
' This call is required by the Windows Forms Designer.
InitializeComponent ()
' Add any initialization after the InitializeComponent () call
End Sub
' Form overrides disposition to clean up the component list.
Protected Overloads Overrides Sub Dispose (ByVal disposing as Boolean)
If disposing Then
If not (components are nothing) Then
Components. Dispose ()
End If
End If
Mybase.dispose (disposing)
End Sub
' Required by the Windows Forms Designer
Private Components as System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Windows Forms Designer
' You can use the Windows Forms Designer to modify this procedure.
' Do not modify it using the Code Editor.
Friend WithEvents NotifyIcon1 as System.Windows.Forms.NotifyIcon
' Create a NotifyIcon instance
Friend TrayIcon = New Icon ("Tray.ico")
' Create an Icon instance
<system.diagnostics.debuggerstepthrough () >
Private Sub InitializeComponent ()
Me.components = New System.ComponentModel.Container ()
Me.notifyicon1 = New System.Windows.Forms.NotifyIcon (me.components)
Me.NotifyIcon1.Text = "NotifyIcon1"
Me.NotifyIcon1.Visible = True
' Assign value to icon property of NotifyIcon instance, complete simple pallet program
Me.NotifyIcon1.Icon = TrayIcon
Me.autoscalebasesize = New System.Drawing.Size (6, 14)
Me.clientsize = New System.Drawing.Size (292, 273)
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
End Class
' Start Program
Module Module1
Sub Main ()
Application.Run (New Form1 ())
End Sub
End Module
But this tray program is not really a tray program, because it has a lot of specific features did not implement, listed below these features, and introduce specific implementation methods
(1). After the tray program is hidden, the program should not be displayed in the taskbar, and the window will not be displayed after running normally:
This is done by setting the properties of the form, as follows:
'设定程序不应该显示在任务栏
Me.ShowInTaskbar = False
'设定程序运行后最小化
Me.WindowState = System.Windows.Forms.FormWindowState.Minimized