-
-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathNotificationArea.cs
More file actions
97 lines (80 loc) · 3.04 KB
/
NotificationArea.cs
File metadata and controls
97 lines (80 loc) · 3.04 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
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
using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
namespace XrmToolBox.Extensibility.UserControls
{
public partial class NotificationArea : UserControl
{
private Uri moreInfoUri;
public NotificationArea()
{
InitializeComponent();
AddBackcolorChangedEvent(this);
AddForecolorChangedEvent(this);
}
private void AddBackcolorChangedEvent(Control control)
{
control.BackColorChanged += NotificationArea_BackColorChanged;
foreach (Control childControl in control.Controls)
{
childControl.BackColorChanged += NotificationArea_BackColorChanged;
AddBackcolorChangedEvent(childControl);
}
}
private void AddForecolorChangedEvent(Control control)
{
control.ForeColorChanged += NotificationArea_ForeColorChanged;
foreach (Control childControl in control.Controls)
{
childControl.ForeColorChanged += NotificationArea_ForeColorChanged;
AddForecolorChangedEvent(childControl);
}
}
private void NotificationArea_ForeColorChanged(object sender, EventArgs e)
{
var ctrl = (Control)sender;
ctrl.ForeColorChanged -= NotificationArea_ForeColorChanged;
ctrl.ForeColor = SystemColors.ControlText;
ctrl.ForeColorChanged += NotificationArea_ForeColorChanged;
}
private void NotificationArea_BackColorChanged(object sender, EventArgs e)
{
var ctrl = (Control)sender;
ctrl.BackColorChanged -= NotificationArea_BackColorChanged;
ctrl.BackColor = SystemColors.Info;
ctrl.BackColorChanged += NotificationArea_BackColorChanged;
}
private void Initialize(string message, Uri infoUri, int height = 30)
{
lblMessage.Text = message;
Height = height;
llLearMore.Visible = infoUri != null;
moreInfoUri = infoUri;
Visible = true;
}
public void ShowInfoNotification(string message, Uri infoUri, int height = 30)
{
Initialize(message, infoUri, height);
pbNotif.Image = Icons.notif_icn_info16;
}
public void ShowWarningNotification(string message, Uri infoUri, int height = 30)
{
Initialize(message, infoUri, height);
pbNotif.Image = Icons.notif_icn_alert16;
}
public void ShowErrorNotification(string message, Uri infoUri, int height = 30)
{
Initialize(message, infoUri, height);
pbNotif.Image = Icons.notif_icn_crit16;
}
private void llDismiss_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Visible = false;
}
private void llLearnMore_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(moreInfoUri.AbsoluteUri);
}
}
}