forked from jaysonragasa/MultiRDPClient.NET
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInfoWindow.cs
More file actions
260 lines (210 loc) · 7.34 KB
/
InfoWindow.cs
File metadata and controls
260 lines (210 loc) · 7.34 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
* LiveInformationBox 2.0
* by Jayson Ragasa aka Nullstring
* Baguio City, Philippines
* -
*
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Reflection;
using Win32APIs;
namespace LiveInformationBox
{
public partial class InfoWindow : Form
{
private const int CS_DROPSHADOW = 0x00020000;
private const int WS_EX_NOACTIVATE = 0x08000000;
private const int WS_EX_TOPMOST = 0x00000008;
protected override CreateParams CreateParams
{
get
{
CreateParams p = base.CreateParams;
p.ClassStyle |= CS_DROPSHADOW;
p.ExStyle = (WS_EX_NOACTIVATE | WS_EX_TOPMOST);
//p.Param = IntPtr.Zero;
return p;
}
}
public enum WindowPositions
{
TOP_LEFT = 0,
TOP_RIGHT = 1,
BOTTOM_LEFT = 2,
BOTTOM_RIGHT = 3
};
const int WinMargin_X = 24;
const int WinMargin_Y = 24;
private string _xmlInfoFile = string.Empty;
private WindowPositions _winpos = WindowPositions.BOTTOM_RIGHT;
private bool _enableInfoWin = false;
public InfoWindow(string XMLInfoFile, WindowPositions winpos)
{
if (File.Exists(XMLInfoFile))
{
this._xmlInfoFile = XMLInfoFile;
this._winpos = winpos;
InitializeComponent();
this.FormClosing += new FormClosingEventHandler(InfoWindow_FormClosing);
this.Paint += new PaintEventHandler(InfoWindow_Paint);
this.Resize += new EventHandler(InfoWindow_Resize);
tmr.Interval = 5000;
tmr.Tick += new EventHandler(tmr_Tick);
btnClose.Click += new EventHandler(btnClose_Click);
}
}
#region control extra properties
public bool EnableInformationWindow
{
set
{
this._enableInfoWin = value;
}
get
{
return this._enableInfoWin;
}
}
#endregion
#region local events
void tmr_Tick(object sender, EventArgs e)
{
HideWindow();
}
void InfoWindow_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
HideWindow();
}
void InfoWindow_Paint(object sender, PaintEventArgs e)
{
Brush brGradient = new System.Drawing.Drawing2D.LinearGradientBrush(this.ClientRectangle, Color.White, Color.FromArgb(228, 228,240), 90, false);
e.Graphics.FillRectangle(brGradient, this.ClientRectangle);
ControlPaint.DrawBorder(e.Graphics, this.ClientRectangle, Color.FromKnownColor(KnownColor.ActiveBorder), ButtonBorderStyle.Solid);
this.lblInfo.BackColor = Color.Transparent;
}
void InfoWindow_Resize(object sender, EventArgs e)
{
this.Invalidate();
}
void btnClose_Click(object sender, EventArgs e)
{
HideWindow();
}
#endregion
#region host control events
private void c_MouseLeave(object sender, EventArgs e)
{
//this.Hide();
}
private void c_MouseHover(object sender, EventArgs e)
{
Type t = sender.GetType();
PropertyInfo piName = t.GetProperty("Name");
if (piName != null)
{
string controlName = piName.GetValue(sender, null).ToString();
XMLInformationReader xmlinforeader = new XMLInformationReader(this._xmlInfoFile);
InformationDetails infoDet = xmlinforeader.Read(controlName);
if (infoDet != null)
{
lblTitle.Text = infoDet.Title;
lblShortDescription.Text = infoDet.ShortDescription;
lblInfo.Text = infoDet.Information;
ShowWindow();
}
}
}
#endregion
#region methods
public void AddControl(object[] ctr)
{
//BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
foreach (object o in ctr)
{
Type t = o.GetType();
EventInfo eiMouseHover = t.GetEvent("MouseHover");
if (eiMouseHover != null)
{
eiMouseHover.AddEventHandler(o, new EventHandler(c_MouseHover));
}
EventInfo eiMouseLeave = t.GetEvent("MouseLeave");
if (eiMouseLeave != null)
{
eiMouseLeave.AddEventHandler(o, new EventHandler(c_MouseLeave));
}
}
}
void HideWindow()
{
this.Hide();
tmr.Enabled = false;
}
void ShowWindow()
{
if (!this._enableInfoWin)
{
return;
}
tmr.Enabled = true;
#region resize window
{
int margin_x = 10;
int margin_y = 10;
lblInfo.Location = new Point(margin_x, panel1.Height + margin_y);
System.Drawing.Size s = new Size();
s.Height = lblInfo.Top + lblInfo.Height + margin_y;
if (lblInfo.Left + lblInfo.Width >= this.Width)
{
s.Width = (margin_x + lblInfo.Width) + margin_x;
}
else
{
s.Width = this.ClientSize.Width;
}
this.ClientSize = s;
//this.Show();
APIs.ShowInactiveTopmost(this.Handle);
}
#endregion
#region window postition
{
switch (this._winpos)
{
case WindowPositions.TOP_LEFT:
this.Location = new Point(
WinMargin_X,
WinMargin_Y
);
break;
case WindowPositions.TOP_RIGHT:
this.Location = new Point(
(Screen.PrimaryScreen.WorkingArea.Width - this.Width) - WinMargin_X,
WinMargin_Y
);
break;
case WindowPositions.BOTTOM_LEFT:
this.Location = new Point(
WinMargin_X,
(Screen.PrimaryScreen.WorkingArea.Height - this.Height) - WinMargin_Y
);
break;
case WindowPositions.BOTTOM_RIGHT:
this.Location = new Point(
(Screen.PrimaryScreen.WorkingArea.Width - this.Width) - WinMargin_X,
(Screen.PrimaryScreen.WorkingArea.Height - this.Height) - WinMargin_Y
);
break;
}
}
#endregion
}
#endregion
}
}