Toasts – Diff between revs 33 and 34
?pathlinks?
Rev 33 | Rev 34 | |||
---|---|---|---|---|
Line 1... | Line 1... | |||
1 | // =====COPYRIGHT===== |
1 | // =====COPYRIGHT===== |
|
2 | // Code originally retrieved from http://www.vbforums.com/showthread.php?t=547778 - no license information supplied |
2 | // Code originally retrieved from http://www.vbforums.com/showthread.php?t=547778 - no license information supplied |
|
3 | // =====COPYRIGHT===== |
3 | // =====COPYRIGHT===== |
|
Line -... | Line 4... | |||
- | 4 | |
||
4 | |
5 | using Markdig.Extensions.Tables; |
|
5 | using System; |
6 | using System; |
|
6 | using System.Collections.Concurrent; |
7 | using System.Collections.Concurrent; |
|
7 | using System.Collections.Generic; |
8 | using System.Collections.Generic; |
|
8 | using System.Diagnostics; |
9 | using System.Diagnostics; |
|
9 | using System.Drawing; |
10 | using System.Drawing; |
|
10 | using System.IO; |
11 | using System.IO; |
|
11 | using System.Linq; |
12 | using System.Linq; |
|
- | 13 | using System.Media; |
||
12 | using System.Media; |
14 | using System.Runtime.InteropServices; |
|
13 | using System.Threading; |
15 | using System.Threading; |
|
14 | using System.Threading.Tasks; |
16 | using System.Threading.Tasks; |
|
- | 17 | using System.Windows.Forms; |
||
15 | using System.Windows.Forms; |
18 | using TheArtOfDev.HtmlRenderer.WinForms; |
|
- | 19 | using Toasts.Properties; |
||
Line 16... | Line 20... | |||
16 | using Toasts.Properties; |
20 | using static System.Windows.Forms.VisualStyles.VisualStyleElement; |
|
17 | |
21 | |
|
18 | namespace Toasts |
22 | namespace Toasts |
|
19 | { |
23 | { |
|
Line 49... | Line 53... | |||
49 | /// |
53 | /// |
|
50 | /// </summary> |
54 | /// </summary> |
|
51 | /// <remarks>clone the image for safety</remarks> |
55 | /// <remarks>clone the image for safety</remarks> |
|
52 | public Image Image |
56 | public Image Image |
|
53 | { |
57 | { |
|
- | 58 | get |
||
- | 59 | { |
||
- | 60 | if (imageBox.Image == null) |
||
- | 61 | { |
||
- | 62 | return null; |
||
- | 63 | } |
||
54 | get => new Bitmap(imageBox.Image); |
64 | return new Bitmap(imageBox.Image); |
|
- | 65 | } |
||
55 | set => imageBox.Image = value; |
66 | set => imageBox.Image = value; |
|
56 | } |
67 | } |
|
Line 57... | Line 68... | |||
57 | |
68 | |
|
Line 66... | Line 77... | |||
66 | #endregion |
77 | #endregion |
|
Line 67... | Line 78... | |||
67 | |
78 | |
|
Line 68... | Line 79... | |||
68 | #region Private Overrides |
79 | #region Private Overrides |
|
69 | |
- | ||
70 | protected override bool ShowWithoutActivation => true; |
80 | |
|
71 | |
81 | protected override bool ShowWithoutActivation => true; |
|
72 | protected override CreateParams CreateParams |
82 | protected override CreateParams CreateParams |
|
73 | { |
83 | { |
|
- | 84 | get |
||
74 | get |
85 | { |
|
75 | { |
86 | |
|
76 | var baseParams = base.CreateParams; |
87 | var baseParams = base.CreateParams; |
|
77 | |
88 | |
|
78 | const int WS_EX_NOACTIVATE = 0x08000000; |
89 | const int WS_EX_NOACTIVATE = 0x08000000; |
|
79 | const int WS_EX_TOOLWINDOW = 0x00000080; |
90 | const int WS_EX_TOOLWINDOW = 0x00000080; |
|
80 | const int WS_EX_TOPMOST = 0x00000008; |
91 | const int WS_EX_TOPMOST = 0x00000008; |
|
81 | baseParams.ExStyle |= WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST; |
92 | baseParams.ExStyle |= WS_EX_NOACTIVATE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST; |
|
82 | |
93 | |
|
83 | return baseParams; |
94 | return baseParams; |
|
Line 84... | Line 95... | |||
84 | } |
95 | } |
|
Line 89... | Line 100... | |||
89 | #region Constructors, Destructors and Finalizers |
100 | #region Constructors, Destructors and Finalizers |
|
Line 90... | Line 101... | |||
90 | |
101 | |
|
91 | private ToastForm() |
102 | private ToastForm() |
|
92 | { |
103 | { |
|
- | 104 | InitializeComponent(); |
||
93 | InitializeComponent(); |
105 | // round rectangles |
|
94 | Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); |
106 | //Region = Region.FromHrgn(NativeMethods.CreateRoundRectRgn(0, 0, Width - 5, Height - 5, 20, 20)); |
|
95 | |
107 | |
|
96 | _screenWidth = Screen.PrimaryScreen.WorkingArea.Width; |
108 | _screenWidth = Screen.PrimaryScreen.WorkingArea.Width; |
|
Line 97... | Line 109... | |||
97 | _screenHeight = Screen.PrimaryScreen.WorkingArea.Height; |
109 | _screenHeight = Screen.PrimaryScreen.WorkingArea.Height; |
|
Line 188... | Line 200... | |||
188 | |
200 | |
|
189 | try |
201 | try |
|
190 | { |
202 | { |
|
191 | lock (OpenNotificationsLock) |
203 | lock (OpenNotificationsLock) |
|
- | 204 | { |
||
- | 205 | Invoke(new MethodInvoker(() => |
||
- | 206 | { |
||
- | 207 | // if not image is provided, just collapse the panel for the extra space |
||
- | 208 | if (imageBox.Image == null) |
||
- | 209 | { |
||
- | 210 | splitContainer1.Panel1Collapsed = true; |
||
- | 211 | } |
||
- | 212 | |
||
- | 213 | // compute notification height from body |
||
- | 214 | var maxWidth = tableLayoutPanel4.Width; |
||
- | 215 | htmlPanel1.MaximumSize = new Size(maxWidth, Screen.PrimaryScreen.WorkingArea.Height); |
||
- | 216 | using (var m_Bitmap = new Bitmap(64, 64)) |
||
- | 217 | { |
||
- | 218 | PointF point = new PointF(0, 0); |
||
- | 219 | SizeF maxSize = new SizeF(maxWidth, Screen.PrimaryScreen.WorkingArea.Height); |
||
- | 220 | using (var graphics = Graphics.FromImage(m_Bitmap)) |
||
- | 221 | { |
||
- | 222 | var size = HtmlRender.Render(graphics, htmlPanel1.Text, point, maxSize); |
||
- | 223 | // total height = height of text fitting in rectangle + the height of the title on top + one extra line for the last line wrap |
||
- | 224 | Height = (int)Math.Round(size.Height) + labelTitle.Height + (int)Math.Round(htmlPanel1.Font.GetHeight()); |
||
- | 225 | } |
||
- | 226 | } |
||
- | 227 | })); |
||
192 | { |
228 | |
|
Line 193... | Line 229... | |||
193 | var notifications = OpenNotifications.ToArray(); |
229 | var notifications = OpenNotifications.ToArray(); |
|
194 | |
230 | |
|
195 | foreach (var openForm in notifications) |
231 | foreach (var openForm in notifications) |
|
Line 231... | Line 267... | |||
231 | })); |
267 | })); |
|
232 | } |
268 | } |
|
Line 233... | Line 269... | |||
233 | |
269 | |
|
234 | Invoke(new MethodInvoker(() => |
270 | Invoke(new MethodInvoker(() => |
|
- | 271 | { |
||
235 | { |
272 | // set the location of the toast |
|
236 | Location = new Point(_screenWidth - Width, _screenHeight - Height); |
273 | Location = new Point(_screenWidth - Width, _screenHeight - Height); |
|
Line 237... | Line 274... | |||
237 | })); |
274 | })); |
|
Line 279... | Line 316... | |||
279 | break; |
316 | break; |
|
280 | case FormAnimator.AnimationDirection.Right: |
317 | case FormAnimator.AnimationDirection.Right: |
|
281 | _formAnimator.Direction = FormAnimator.AnimationDirection.Left; |
318 | _formAnimator.Direction = FormAnimator.AnimationDirection.Left; |
|
282 | break; |
319 | break; |
|
283 | } |
320 | } |
|
284 | |
321 | |
|
285 | _showFormTaskCompletionSource.TrySetResult(new { }); |
322 | _showFormTaskCompletionSource.TrySetResult(new { }); |
|
286 | } |
323 | } |
|
Line 287... | Line 324... | |||
287 | |
324 | |
|
288 | private async void ToastTimer_Elapsed(object sender, EventArgs e) |
325 | private async void ToastTimer_Elapsed(object sender, EventArgs e) |