From 5b456c14a736825f02f8c125ee2de15bcc0e5814 Mon Sep 17 00:00:00 2001 From: mshafer1 <2565361+mshafer1@users.noreply.github.com> Date: Sat, 21 Dec 2024 08:18:57 -0600 Subject: [PATCH] utilize modern c# features --- ntfysh_client/NotificationDialog.cs | 37 +++++++---------------------- 1 file changed, 9 insertions(+), 28 deletions(-) diff --git a/ntfysh_client/NotificationDialog.cs b/ntfysh_client/NotificationDialog.cs index 2c913a7..dae40dd 100644 --- a/ntfysh_client/NotificationDialog.cs +++ b/ntfysh_client/NotificationDialog.cs @@ -119,10 +119,7 @@ namespace ntfysh_client private void UpdateProgress(object? sender, EventArgs e) { - if (_shownStopwatch == null) - { - return; - } + if (_shownStopwatch is null) return; progress = (int)((_timeout - _shownStopwatch.ElapsedMilliseconds) * 100 / _timeout); lbTimeout.Text = $"{(int)(_timeout - _shownStopwatch.ElapsedMilliseconds) / 1000}"; @@ -146,11 +143,6 @@ namespace ntfysh_client base.SetVisibleCore(value); } - protected override void OnShown(EventArgs e) - { - base.OnShown(e); - } - private void SetWindowPosition() { int workingtop = Screen.PrimaryScreen.WorkingArea.Height - Height; @@ -188,21 +180,13 @@ namespace ntfysh_client } } - private Image? ConvertToolTipIconToImage(ToolTipIcon icon) + private Image? ConvertToolTipIconToImage(ToolTipIcon icon) => icon switch { - switch (icon) - { - case ToolTipIcon.Info: - return SystemIcons.Information.ToBitmap(); - case ToolTipIcon.Warning: - return SystemIcons.Warning.ToBitmap(); - case ToolTipIcon.Error: - return SystemIcons.Error.ToBitmap(); - case ToolTipIcon.None: - default: - return null; - } - } + ToolTipIcon.Info => SystemIcons.Information.ToBitmap(), + ToolTipIcon.Warning => SystemIcons.Warning.ToBitmap(), + ToolTipIcon.Error => SystemIcons.Error.ToBitmap(), + _ => null + }; private void InitializeWindowHidden() { @@ -231,11 +215,8 @@ namespace ntfysh_client public const int AW_BLEND = 0x00080000; } - private void window_MouseDown(object sender, EventArgs e) - { - CancelTimer(); - } - + private void window_MouseDown(object sender, EventArgs e) => CancelTimer(); + private void CancelTimer() { if (InvokeRequired)