Vb. NET implementation form icon minimized to status bar

Source: Internet
Author: User
Tags net visual studio

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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.