Share vb.net notifyicon,

leminh.khai

New member
#vb.net #Notifyicon #WindowsForm #GUI #VisualBasic ** vb.net notifyicon **

Thông báo là một biểu tượng nhỏ có thể được hiển thị trong khu vực khay hệ thống của Thanh tác vụ Windows.Nó có thể được sử dụng để hiển thị thông tin trạng thái, chẳng hạn như số lượng email chưa đọc hoặc mức âm lượng hiện tại.Thông báo cũng có thể được sử dụng để khởi chạy các ứng dụng hoặc mở các trang web cụ thể.

Để tạo một thông báo trong vb.net, bạn có thể sử dụng các bước sau:

1. ** Nhập hệ thống.windows.forms không gian tên. **

`` `VBNet
Nhập khẩu System.Windows.Forms
`` `

2. ** Tạo một đối tượng Thông báo mới. **

`` `VBNet
Thông báo dim
`` `

3. ** Đặt thuộc tính của Thông báo. **

Bạn có thể đặt các thuộc tính sau của một thông báo:

*** Biểu tượng: ** Biểu tượng sẽ được hiển thị trong khay hệ thống.
*** Văn bản: ** Văn bản sẽ được hiển thị bên dưới biểu tượng.
*** Mẹo bóng: ** Văn bản sẽ được hiển thị trong một đầu bóng khi người dùng di chuyển trên biểu tượng.
*** Có thể nhìn thấy: ** Có thể nhìn thấy thông báo hay không.

Ví dụ: mã sau đây đặt biểu tượng, văn bản và đầu bóng của một thông báo:

`` `VBNet
notifyicon.icon = biểu tượng mới ("c: \ path \ to \ icon.ico")
notifyicon.text = "của tôi thông báo"
notifyicon.balloontiptext = "Đây là một thông báo."
notifyicon.visible = true
`` `

4. ** Thêm thông báo vào khay hệ thống. **

Bạn có thể thêm một thông báo vào khay hệ thống bằng cách gọi phương thức `Thêm` của thuộc tính` notifyicon.trayiconcollection`.

`` `VBNet
notifyicon.trayiconcollection.add (Thông báo
`` `

5. ** Xử lý các sự kiện của Thông báo. **

Thông báo cho thấy một số sự kiện mà bạn có thể xử lý, chẳng hạn như `mouseclick`,` mousedoubleclick` và `balloontipclicky`.Bạn có thể xử lý các sự kiện này bằng cách thêm trình xử lý sự kiện vào `click`,` DoubleClick` và `balloontipclicky`.

Ví dụ: mã sau đây xử lý sự kiện `mouseClick` của notifyicon:

`` `VBNet
Private Sub notifyicon_mouseClick (người gửi dưới dạng đối tượng, e như mouseEventargs) xử lý thông báo.
'Làm điều gì đó khi người dùng nhấp vào Thông báo.
Kết thúc phụ
`` `

**Ví dụ**

Mã sau đây hiển thị một ví dụ về một thông báo hiển thị số lượng email chưa đọc trong khay hệ thống.

`` `VBNet
Nhập khẩu System.Windows.Forms

Lớp công khai Mẫu1

Công khai Sub mới ()
Khởi tạo ()

'Tạo một đối tượng Thông báo.
Thông báo dim

'Đặt các thuộc tính của thông báo.
notifyicon.icon = biểu tượng mới ("c: \ path \ to \ icon.ico")
notifyicon.text = "của tôi thông báo"
notifyicon.balloontiptext = "Bạn có 5 email chưa đọc."
notifyicon.visible = true

'Thêm thông báo vào khay hệ thống.
notifyicon.trayiconcollection.add (Thông báo

'Xử lý các sự kiện của thông báo.
notifyicon.
notifyicon.balloontipclicky += new EventHandler (địa chỉ notifyicon_balloontipclicky)
Kết thúc phụ

Private Sub notifyicon_mouseClick (người gửi dưới dạng đối tượng, e như mouseEventargs) xử lý thông báo.
=======================================
#vb.net #Notifyicon #WindowsForm #gui #VisualBasic **VB.NET NotifyIcon**

A NotifyIcon is a small icon that can be displayed in the system tray area of the Windows taskbar. It can be used to display status information, such as the number of unread emails or the current volume level. NotifyIcons can also be used to launch applications or open specific websites.

To create a NotifyIcon in VB.NET, you can use the following steps:

1. **Import the System.Windows.Forms namespace.**

```vbnet
Imports System.Windows.Forms
```

2. **Create a new NotifyIcon object.**

```vbnet
Dim notifyIcon As New NotifyIcon()
```

3. **Set the NotifyIcon's properties.**

You can set the following properties of a NotifyIcon:

* **Icon:** The icon that will be displayed in the system tray.
* **Text:** The text that will be displayed below the icon.
* **Balloon Tip:** The text that will be displayed in a balloon tip when the user hovers over the icon.
* **Visible:** Whether or not the NotifyIcon is visible.

For example, the following code sets the icon, text, and balloon tip of a NotifyIcon:

```vbnet
notifyIcon.Icon = New Icon("C:\path\to\icon.ico")
notifyIcon.Text = "My NotifyIcon"
notifyIcon.BalloonTipText = "This is a NotifyIcon."
notifyIcon.Visible = True
```

4. **Add the NotifyIcon to the system tray.**

You can add a NotifyIcon to the system tray by calling the `Add` method of the `NotifyIcon.TrayIconCollection` property.

```vbnet
notifyIcon.TrayIconCollection.Add(notifyIcon)
```

5. **Handle the NotifyIcon's events.**

The NotifyIcon exposes a number of events that you can handle, such as `MouseClick`, `MouseDoubleClick`, and `BalloonTipClicked`. You can handle these events by adding event handlers to the NotifyIcon's `Click`, `DoubleClick`, and `BalloonTipClicked` events.

For example, the following code handles the `MouseClick` event of a NotifyIcon:

```vbnet
Private Sub notifyIcon_MouseClick(sender As Object, e As MouseEventArgs) Handles notifyIcon.MouseClick
' Do something when the user clicks the NotifyIcon.
End Sub
```

**Example**

The following code shows an example of a NotifyIcon that displays the number of unread emails in the system tray.

```vbnet
Imports System.Windows.Forms

Public Class Form1

Public Sub New()
InitializeComponent()

' Create a NotifyIcon object.
Dim notifyIcon As New NotifyIcon()

' Set the NotifyIcon's properties.
notifyIcon.Icon = New Icon("C:\path\to\icon.ico")
notifyIcon.Text = "My NotifyIcon"
notifyIcon.BalloonTipText = "You have 5 unread emails."
notifyIcon.Visible = True

' Add the NotifyIcon to the system tray.
notifyIcon.TrayIconCollection.Add(notifyIcon)

' Handle the NotifyIcon's events.
notifyIcon.MouseClick += New EventHandler(AddressOf notifyIcon_MouseClick)
notifyIcon.BalloonTipClicked += New EventHandler(AddressOf notifyIcon_BalloonTipClicked)
End Sub

Private Sub notifyIcon_MouseClick(sender As Object, e As MouseEventArgs) Handles notifyIcon.
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top