The programming environment used in this article is Microsoft Visual Studio 2005, which first opens Visual Studio. On the File menu, click New Project. In the Templates pane of the New Project dialog box, click Windows Application (Windows application). Click OK (OK).
To automatically hide the form icon when you minimize it to the taskbar, we can use a control whose name is called the NotifyIcon control, and open the toolbox on the left to find the NotifyIcon control and drag it directly onto the form. Set the Icon property of the NotifyIcon, of course the icon property you can set a good looking icons.
Will down click the Form1 form, enter the property setting to set the form's windowstate to minimized; The ShowInTaskbar property is set to False. Figure 2
Next we're going to enter the code.
In the resize code event of the form,
The following are the referenced contents: Private Sub form1_resize (ByVal sender as Object, ByVal e as System.EventArgs) Handles mybase.resize If me.windowstate = formwindowstate.minimized Then Me.hide () End If End Sub |
The code means that when the form is minimized, it is automatically hidden in the status bar.
The form is automatically hidden and appears in the status bar when it is running.
To display a form when you double-click the icon you can set the DoubleClick code for the NotifyIcon control
The code is as follows:
The following are the referenced contents: Private Sub Notifyicon1_doubleclick (ByVal sender as Object, ByVal e as System.EventArgs) Handles Notifyicon1.doubleclick Me.showintaskbar = True Me.Show () Me.windowstate = Formwindowstate.normal End Sub |
If we want to create a right-click menu, we can add a ContextMenuStrip control to the form and associate it with the NotifyIcon ContextMenu property. Select menus and toolbars in the Toolbox, drag the ContextMenu control directly onto the form to enter the property settings, and enter the corresponding menu keyword (the version of the software you want to enter as shown below).
Figure 3
Then click the form's NotifyIcon1 control, set the properties, and select the right-click menu ContextMenustrip1 to associate at ContextMenuStrip. See Figure 4
Then press F5 to run the program, click the form to minimize the button, the form's icon automatically hidden to the status bar. Right-click you can see the beautifully right-click menu.