From e24ef645acf70eae1d06c1dc55767d36882c82e2 Mon Sep 17 00:00:00 2001 From: mshafer1 <2565361+mshafer1@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:32:19 -0600 Subject: [PATCH] implement icon --- ntfysh_client/MainForm.cs | 4 +--- ntfysh_client/NotificationDialog.Designer.cs | 17 ++++++++++++-- ntfysh_client/NotificationDialog.cs | 24 +++++++++++++++++++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/ntfysh_client/MainForm.cs b/ntfysh_client/MainForm.cs index 332dfe6..d5906bd 100644 --- a/ntfysh_client/MainForm.cs +++ b/ntfysh_client/MainForm.cs @@ -73,9 +73,7 @@ namespace ntfysh_client string finalTitle = string.IsNullOrWhiteSpace(e.Title) ? $"{e.Sender.TopicId}@{e.Sender.ServerUrl}" : e.Title; - //notifyIcon.ShowBalloonTip((int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds, finalTitle, e.Message, priorityIcon); - //this.notificationDialog.IsVisible = true; - this.notificationDialog.ShowNotification(finalTitle, e.Message, (int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds); + this.notificationDialog.ShowNotification(finalTitle, e.Message, (int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds, priorityIcon); } private void OnConnectionMultiAttemptFailure(NotificationListener sender, SubscribedTopic topic) diff --git a/ntfysh_client/NotificationDialog.Designer.cs b/ntfysh_client/NotificationDialog.Designer.cs index 9cb3494..8718f50 100644 --- a/ntfysh_client/NotificationDialog.Designer.cs +++ b/ntfysh_client/NotificationDialog.Designer.cs @@ -31,6 +31,8 @@ tbTitle = new System.Windows.Forms.TextBox(); button1 = new System.Windows.Forms.Button(); tbMessage = new System.Windows.Forms.TextBox(); + iconBox = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)iconBox).BeginInit(); SuspendLayout(); // // tbTitle @@ -38,10 +40,10 @@ tbTitle.BackColor = System.Drawing.SystemColors.ControlDark; tbTitle.BorderStyle = System.Windows.Forms.BorderStyle.None; tbTitle.Font = new System.Drawing.Font("Segoe UI", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point); - tbTitle.Location = new System.Drawing.Point(12, 19); + tbTitle.Location = new System.Drawing.Point(54, 13); tbTitle.Name = "tbTitle"; tbTitle.ReadOnly = true; - tbTitle.Size = new System.Drawing.Size(725, 32); + tbTitle.Size = new System.Drawing.Size(683, 32); tbTitle.TabIndex = 0; // // button1 @@ -70,18 +72,28 @@ tbMessage.Size = new System.Drawing.Size(725, 253); tbMessage.TabIndex = 2; // + // iconBox + // + iconBox.Location = new System.Drawing.Point(12, 12); + iconBox.Name = "iconBox"; + iconBox.Size = new System.Drawing.Size(36, 39); + iconBox.TabIndex = 3; + iconBox.TabStop = false; + // // NotificationDialog // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; BackColor = System.Drawing.SystemColors.ControlDark; ClientSize = new System.Drawing.Size(800, 450); + Controls.Add(iconBox); Controls.Add(tbMessage); Controls.Add(button1); Controls.Add(tbTitle); FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; Name = "NotificationDialog"; Text = "NotificationDialog"; + ((System.ComponentModel.ISupportInitialize)iconBox).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -91,5 +103,6 @@ private System.Windows.Forms.TextBox tbTitle; private System.Windows.Forms.Button button1; private System.Windows.Forms.TextBox tbMessage; + private System.Windows.Forms.PictureBox iconBox; } } \ No newline at end of file diff --git a/ntfysh_client/NotificationDialog.cs b/ntfysh_client/NotificationDialog.cs index b790a4d..aac9b97 100644 --- a/ntfysh_client/NotificationDialog.cs +++ b/ntfysh_client/NotificationDialog.cs @@ -21,6 +21,7 @@ namespace ntfysh_client private const int ScreenMargin = 20; private System.Timers.Timer? timer = null; + private ToolTipIcon? _icon; private void SetWindowPosition() { @@ -68,8 +69,13 @@ namespace ntfysh_client } } - public void ShowNotification(string title, string message, int timeout_ms=-1) + public void ShowNotification(string title, string message, int timeout_ms = -1, ToolTipIcon? icon = null) { + this._icon = icon; + if (this._icon != null) + { + this.iconBox.Image = ConvertToolTipIconToImage(_icon.Value); + } if (this.timer != null) { this.timer.Stop(); @@ -87,6 +93,22 @@ namespace ntfysh_client this.SetWindowPosition(); } + private Image? ConvertToolTipIconToImage(ToolTipIcon icon) + { + 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; + } + } + public bool IsVisible { get { return this.Visible; }