0 امتیاز
402 بازدید
در VB.Net توسط مدیر کل (15.6k امتیاز)

Start an new project

image

You can also add an icon to your application. I have added also a label and changed its text property to System Tray:

image

Go to the toolbox and a ContextMenuStrip:

image

Fill up to important menus inside the first 2 boxex: Show and Exit as shown above.

You can add more menus depends on the project you are working on.

Add a NotifyIcon to the form:

image

Once you add NotifyIcon, you should have 2 icons in gray area: ContextMenuStrip and NotifyIcon as below:

image

It is important that you add an icon to the NotifyIcon so that when the program is running in the Notification Area you will be able to recognize it.

To do that right click on NotifyIcon in the gray area then click on properties:

Then go to Properties window on the and click next to Icon. Browse your computer to your desired icon.

On the same window, change the ContextMenuStrip to ContextMenuStrip1:

image

Let's now start adding the codes to the program:

First we should make sure that ContextMenuStrip is not enabled when the program starts:

Double click on the form and that should take you to the code page:

Add the following load event:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     ContextMenuStrip1.Enabled = False
End Sub

Then Add the following code so that when the form closes by the user, it stays running in the notification area:

 Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        'Cancel Closing:
        e.Cancel = True
        'Minimize the form:
        Me.WindowState = FormWindowState.Minimized
        'Don't show in the task bar
        Me.ShowInTaskbar = False
        'Enable the Context Menu Strip
        ContextMenuStrip1.Enabled = True
    End Sub

Then add a code to the Show Menu of the ContextMenuStip1:

 Private Sub ShowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowToolStripMenuItem.Click
        'When Show menu clicks, it will show the form:
        Me.WindowState = FormWindowState.Normal
        'Show in the task bar:
        Me.ShowInTaskbar = True
        'Disable the Context Menu:
        ContextMenuStrip1.Enabled = False
    End Sub

Add a Code to the Exit menu so that when it clicks it the program exits:

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
     End
End Sub

Add a code so that when the form minimizes, it disappears from the task bar, and run in the notification area:

Private Sub Form1_SizeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
        If Me.WindowState = FormWindowState.Minimized Then
            ShowInTaskbar = False
            ContextMenuStrip1.Enabled = True
        End If
    End Sub

Run the program and you should see an icon in the notification area for your project.

http://www.visual-basic-tutorials.com/form/System%20Tray.htm

پاسخ شما

حریم شخصی : آدرس ایمیل شما محفوظ میماند و برای استفاده های تجاری و تبلیغاتی به کار نمی رود
FOXNET محلی برای دانستن واشتراک مطالبی که نمی دانستید

سوالات مشابه

0 امتیاز
0 پاسخ 235 بازدید
سوال شده فوریه 15, 2022 در لینوکس توسط admin مدیر کل (15.6k امتیاز)
0 امتیاز
0 پاسخ 4.8k بازدید
سوال شده می 4, 2021 در VB.Net توسط admin مدیر کل (15.6k امتیاز)
0 امتیاز
1 پاسخ 1.3k بازدید
سوال شده Mar 7, 2015 در نرم افزار توسط admin مدیر کل (15.6k امتیاز)
0 امتیاز
1 پاسخ 133 بازدید
0 امتیاز
0 پاسخ 765 بازدید
سوال شده می 5, 2018 در شبکه عمومی توسط admin مدیر کل (15.6k امتیاز)
...