-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotifyIconManager.cs
More file actions
39 lines (32 loc) · 1.08 KB
/
NotifyIconManager.cs
File metadata and controls
39 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Drawing;
using System.Windows.Forms;
public class NotifyIconManager : IDisposable
{
private readonly NotifyIcon _icon;
private readonly MainWindow _window;
public NotifyIconManager(MainWindow window)
{
_window = window;
_icon = new NotifyIcon
{
Icon = new Icon("Resources/app.ico"),
Text = "VLESS Client",
Visible = true
};
_icon.DoubleClick += (s, e) => ShowWindow();
var menu = new ContextMenuStrip();
menu.Items.Add("Показать", null, (s, e) => ShowWindow());
menu.Items.Add("Подключить", null, async (s, e) => await _window.ConnectAsync());
menu.Items.Add("Отключить", null, (s, e) => _window.Disconnect());
menu.Items.Add("Выход", null, (s, e) => Application.Exit());
_icon.ContextMenuStrip = menu;
}
private void ShowWindow()
{
_window.Show();
_window.WindowState = WindowState.Normal;
_window.Activate();
}
public void Dispose() => _icon.Dispose();
}