-
Notifications
You must be signed in to change notification settings - Fork 0
/
NotifyIconWPF.cs
108 lines (98 loc) · 3.85 KB
/
NotifyIconWPF.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.ComponentModel;
using System.Windows.Forms;
namespace NamaAlert
{
public class NotifyIconWPF : Component
{
private ContextMenuStrip _contextMenu;
private NotifyIcon _notifyIcon;
private ToolStripMenuItem MenuItemOpen;
private ToolStripSeparator toolStripSeparator1;
private ToolStripMenuItem MenuItemExit;
private IContainer components;
public string ToolTipText { get { return _notifyIcon.Text; } set { _notifyIcon.Text = value; } }
private MainWindow _mainWindow = new MainWindow();
public NotifyIconWPF()
{
InitializeComponent();
ToolTipText = @"Namalert";
MenuItemOpen.Click += MenuItemOpen_Click;
MenuItemExit.Click += MenuItemExit_Click;
_mainWindow.Show();
_mainWindow.Initialize();
_mainWindow.Hide();
_mainWindow.GetIn();
}
private void MenuItemExit_Click(object sender, EventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
private void MenuItemOpen_Click(object sender, EventArgs e)
{
ShowWindow(_mainWindow);
}
public NotifyIconWPF(IContainer container)
{
container.Add(this);
InitializeComponent();
}
private void ShowWindow(Window win)
{
if (win.WindowState == System.Windows.WindowState.Minimized)
win.WindowState = System.Windows.WindowState.Normal;
win.Show();
win.Activate();
win.ShowInTaskbar = true;
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NotifyIconWPF));
this._contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this._notifyIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.MenuItemOpen = new System.Windows.Forms.ToolStripMenuItem();
this.MenuItemExit = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this._contextMenu.SuspendLayout();
//
// _contextMenu
//
this._contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.MenuItemOpen,
this.toolStripSeparator1,
this.MenuItemExit});
this._contextMenu.Name = "ContextMenu";
this._contextMenu.Size = new System.Drawing.Size(191, 48);
//
// _notifyIcon
//
this._notifyIcon.ContextMenuStrip = this._contextMenu;
this._notifyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("_notifyIcon.Icon")));
this._notifyIcon.Visible = true;
//
// MenuItemOpen
//
this.MenuItemOpen.Name = "MenuItemOpen";
this.MenuItemOpen.Size = new System.Drawing.Size(190, 22);
this.MenuItemOpen.Text = "ウィンドウを表示(&S)";
//
// MenuItemExit
//
this.MenuItemExit.Name = "MenuItemExit";
this.MenuItemExit.Size = new System.Drawing.Size(190, 22);
this.MenuItemExit.Text = "終了(&E)";
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 6);
this._contextMenu.ResumeLayout(false);
}
}
}