-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (65 loc) · 2.17 KB
/
Program.cs
File metadata and controls
71 lines (65 loc) · 2.17 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Dict
{
internal static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// 从托盘图标打开和直接运行速度差不多
// NotifyIcon nicon = CreateNotifyIcon();
// Application.Run();
Application.Run(new WebWindow());
// nicon.Visible = false;
}
private static NotifyIcon CreateNotifyIcon()
{
Form form = null;
var formLock = new object();
void ShowForm()
{
lock (formLock)
{
if (form == null)
{
form = new WebWindow();
form.FormClosed += (o2, evt2) => form = null;
form.Show();
}
}
form.Activate();
}
var menu = new ContextMenuStrip();
menu.Items.Add("显示主窗口", null, (s, e) => ShowForm());
menu.Items.Add(new ToolStripSeparator()); // 添加分隔线
menu.Items.Add("退出程序", null, (s, e) => Application.Exit());
var nicon = new NotifyIcon
{
// 工具箱图标 by Elegantthemes on <a href="https://icon-icons.com/zh/authors/103-elegantthemes">Icon-Icons.com</a>
Icon = Properties.Resources.toolsbox,
Text = "Toolsbox v0.1",
ContextMenuStrip = menu,
Visible = true,
};
nicon.MouseClick += (o, evt) =>
{
if (evt.Button == MouseButtons.Left)
{
ShowForm();
}
};
ShowForm();
return nicon;
}
}
}