-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcessIcon.cs
75 lines (66 loc) · 2.01 KB
/
ProcessIcon.cs
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
72
73
74
75
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using BranchSwitcher.Properties;
namespace BranchSwitcher
{
/// <summary>
///
/// </summary>
class ProcessIcon : IDisposable
{
/// <summary>
/// The NotifyIcon object.
/// </summary>
private readonly NotifyIcon _notifyIcon;
/// <summary>
/// List of branch configurations
/// </summary>
private readonly List<BranchConfig> _branchConfigs = new List<BranchConfig>();
/// <summary>
/// Initializes a new instance of the <see cref="ProcessIcon"/> class.
/// </summary>
public ProcessIcon(List<BranchConfig> branchConfigs)
{
_branchConfigs = branchConfigs;
// Instantiate the NotifyIcon object.
_notifyIcon = new NotifyIcon();
}
/// <summary>
/// Displays the icon in the system tray.
/// </summary>
public void Display()
{
// Put the icon in the system tray and allow it react to mouse clicks.
_notifyIcon.MouseClick += new MouseEventHandler(ni_MouseClick);
_notifyIcon.Icon = Resources.SystemTrayApp;
_notifyIcon.Text = Resources.ProcessIcon_Display_BranchRoot_Switcher;
_notifyIcon.Visible = true;
// Attach a context menu.
_notifyIcon.ContextMenuStrip = new ContextMenus(_branchConfigs).Create();
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
public void Dispose()
{
// When the application closes, this will remove the icon from the system tray immediately.
_notifyIcon.Dispose();
}
/// <summary>
/// Handles the MouseClick event of the ni control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Windows.Forms.MouseEventArgs"/> instance containing the event data.</param>
void ni_MouseClick(object sender, MouseEventArgs e)
{
// Handle mouse button clicks.
if (e.Button == MouseButtons.Left)
{
// Start Windows Explorer.
Process.Start("explorer", null);
}
}
}
}