implement icon

This commit is contained in:
mshafer1
2024-12-20 13:32:19 -06:00
parent f5298e1a4e
commit e24ef645ac
3 changed files with 39 additions and 6 deletions

View File

@@ -73,9 +73,7 @@ namespace ntfysh_client
string finalTitle = string.IsNullOrWhiteSpace(e.Title) ? $"{e.Sender.TopicId}@{e.Sender.ServerUrl}" : e.Title; 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.ShowNotification(finalTitle, e.Message, (int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds, priorityIcon);
//this.notificationDialog.IsVisible = true;
this.notificationDialog.ShowNotification(finalTitle, e.Message, (int)TimeSpan.FromSeconds((double)Program.Settings.Timeout).TotalMilliseconds);
} }
private void OnConnectionMultiAttemptFailure(NotificationListener sender, SubscribedTopic topic) private void OnConnectionMultiAttemptFailure(NotificationListener sender, SubscribedTopic topic)

View File

@@ -31,6 +31,8 @@
tbTitle = new System.Windows.Forms.TextBox(); tbTitle = new System.Windows.Forms.TextBox();
button1 = new System.Windows.Forms.Button(); button1 = new System.Windows.Forms.Button();
tbMessage = new System.Windows.Forms.TextBox(); tbMessage = new System.Windows.Forms.TextBox();
iconBox = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)iconBox).BeginInit();
SuspendLayout(); SuspendLayout();
// //
// tbTitle // tbTitle
@@ -38,10 +40,10 @@
tbTitle.BackColor = System.Drawing.SystemColors.ControlDark; tbTitle.BackColor = System.Drawing.SystemColors.ControlDark;
tbTitle.BorderStyle = System.Windows.Forms.BorderStyle.None; 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.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.Name = "tbTitle";
tbTitle.ReadOnly = true; tbTitle.ReadOnly = true;
tbTitle.Size = new System.Drawing.Size(725, 32); tbTitle.Size = new System.Drawing.Size(683, 32);
tbTitle.TabIndex = 0; tbTitle.TabIndex = 0;
// //
// button1 // button1
@@ -70,18 +72,28 @@
tbMessage.Size = new System.Drawing.Size(725, 253); tbMessage.Size = new System.Drawing.Size(725, 253);
tbMessage.TabIndex = 2; 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 // NotificationDialog
// //
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
BackColor = System.Drawing.SystemColors.ControlDark; BackColor = System.Drawing.SystemColors.ControlDark;
ClientSize = new System.Drawing.Size(800, 450); ClientSize = new System.Drawing.Size(800, 450);
Controls.Add(iconBox);
Controls.Add(tbMessage); Controls.Add(tbMessage);
Controls.Add(button1); Controls.Add(button1);
Controls.Add(tbTitle); Controls.Add(tbTitle);
FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
Name = "NotificationDialog"; Name = "NotificationDialog";
Text = "NotificationDialog"; Text = "NotificationDialog";
((System.ComponentModel.ISupportInitialize)iconBox).EndInit();
ResumeLayout(false); ResumeLayout(false);
PerformLayout(); PerformLayout();
} }
@@ -91,5 +103,6 @@
private System.Windows.Forms.TextBox tbTitle; private System.Windows.Forms.TextBox tbTitle;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox tbMessage; private System.Windows.Forms.TextBox tbMessage;
private System.Windows.Forms.PictureBox iconBox;
} }
} }

View File

@@ -21,6 +21,7 @@ namespace ntfysh_client
private const int ScreenMargin = 20; private const int ScreenMargin = 20;
private System.Timers.Timer? timer = null; private System.Timers.Timer? timer = null;
private ToolTipIcon? _icon;
private void SetWindowPosition() 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) if (this.timer != null)
{ {
this.timer.Stop(); this.timer.Stop();
@@ -87,6 +93,22 @@ namespace ntfysh_client
this.SetWindowPosition(); 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 public bool IsVisible
{ {
get { return this.Visible; } get { return this.Visible; }