Skip to content

Commit

Permalink
notification timer
Browse files Browse the repository at this point in the history
  • Loading branch information
mbnq committed Oct 16, 2024
1 parent e68efe2 commit 0183dc6
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class Program
static Mutex redunDancerMutex = new Mutex(true, "{readunDancer}");

#region variables and constants
public const string mbVersion = "0.0.1.6";
public const string mbVersion = "0.0.1.7";
#endregion

#region DPI
Expand Down
19 changes: 18 additions & 1 deletion core/mbGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,31 @@ private void checkIPSettings()

LogPingResult($"Settings validated correctly: {isConfigCorrect}", true);
}
public void PopUpNotification(string title, string message, int timeout)
public void PopUpNotification_old(string title, string message, int timeout)
{
if (showNotifications)
{
mbNotificationForm notification = new mbNotificationForm(title, message, timeout);
notification.Show();
}
}

public void PopUpNotification(string title, string message, int timeout)
{
if (showNotifications)
{
if (this.InvokeRequired)
{
this.Invoke(new Action(() => PopUpNotification(title, message, timeout)));
}
else
{
mbNotificationForm notification = new mbNotificationForm(title, message, timeout);
notification.Show();
}
}
}

private void StartCheckboxLock()
{
if (int.TryParse(mbTestPingIntervalTextBox.Text, out int interval))
Expand Down
118 changes: 64 additions & 54 deletions core/mbNotification.cs
Original file line number Diff line number Diff line change
@@ -1,75 +1,85 @@

/*
/*
www.mbnq.pl 2024
https://mbnq.pl/
mbnq00 on gmail
*/

using redunDancer;
public class mbNotificationForm : Form
{
private Label mbTitleLabel, mbMessageLabel;
using System;
using System.Drawing;
using System.Windows.Forms;

public mbNotificationForm(string title, string message, int timeout = 3000)
namespace redunDancer
{
public class mbNotificationForm : Form
{
private Label mbTitleLabel, mbMessageLabel;
private System.Windows.Forms.Timer closeTimer;

this.Size = new Size(200, 100);
this.StartPosition = FormStartPosition.Manual;
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
this.TopMost = true;
this.ShowInTaskbar = false;
public mbNotificationForm(string title, string message, int timeout = 3000)
{
this.Size = new Size(200, 100);
this.StartPosition = FormStartPosition.Manual;
this.FormBorderStyle = FormBorderStyle.FixedToolWindow;
this.TopMost = true;
this.ShowInTaskbar = false;

mbTitleLabel = new Label();
mbTitleLabel.Text = title;
mbTitleLabel.AutoSize = false;
mbTitleLabel.TextAlign = ContentAlignment.MiddleCenter;
mbTitleLabel.Dock = DockStyle.Top;
mbTitleLabel.Font = new Font("Consolas", 10, FontStyle.Regular);
mbTitleLabel.Height = 20;
mbTitleLabel.BackColor = Color.Gray;
mbTitleLabel = new Label();
mbTitleLabel.Text = title;
mbTitleLabel.AutoSize = false;
mbTitleLabel.TextAlign = ContentAlignment.MiddleCenter;
mbTitleLabel.Dock = DockStyle.Top;
mbTitleLabel.Font = new Font("Consolas", 10, FontStyle.Regular);
mbTitleLabel.Height = 20;
mbTitleLabel.BackColor = Color.Gray;

mbMessageLabel = new Label();
mbMessageLabel.Text = message;
mbMessageLabel.AutoSize = false;
mbMessageLabel.TextAlign = ContentAlignment.MiddleCenter;
mbMessageLabel.Dock = DockStyle.Fill;
mbMessageLabel.Font = new Font("Consolas", 10);
mbMessageLabel = new Label();
mbMessageLabel.Text = message;
mbMessageLabel.AutoSize = false;
mbMessageLabel.TextAlign = ContentAlignment.MiddleCenter;
mbMessageLabel.Dock = DockStyle.Fill;
mbMessageLabel.Font = new Font("Consolas", 10);

// ---
this.Controls.Add(mbTitleLabel);
this.Controls.Add(mbMessageLabel);
this.Controls.Add(mbTitleLabel);
this.Controls.Add(mbMessageLabel);

int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
this.Location = new Point(screenWidth - this.Width - 10, screenHeight - this.Height - 10);
int screenWidth = Screen.PrimaryScreen.WorkingArea.Width;
int screenHeight = Screen.PrimaryScreen.WorkingArea.Height;
this.Location = new Point(screenWidth - this.Width - 10, screenHeight - this.Height - 10);

this.Click += (s, e) => this.Hide();
mbTitleLabel.Click += (s, e) => this.Hide();
mbMessageLabel.Click += (s, e) => this.Hide();
this.Click += (s, e) => this.Hide();
mbTitleLabel.Click += (s, e) => this.Hide();
mbMessageLabel.Click += (s, e) => this.Hide();

this.Show();
mbKillWithDelay(timeout);
}
private async void mbKillWithDelay(int timeout)
{
await Task.Delay(timeout);
this.Close();
}
closeTimer = new System.Windows.Forms.Timer();
closeTimer.Interval = timeout;
closeTimer.Tick += CloseTimer_Tick;
closeTimer.Start();
}

// ---
protected override bool ShowWithoutActivation
{
get { return true; }
}
protected override CreateParams CreateParams
{
get
private void CloseTimer_Tick(object sender, EventArgs e)
{
closeTimer.Stop();
closeTimer.Dispose();
this.Close();
}

// ---

protected override bool ShowWithoutActivation
{
get { return true; }
}
protected override CreateParams CreateParams
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x08000000; // Prevents the window from activating
return cp;
get
{
const int WS_EX_NOACTIVATE = 0x08000000;
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_NOACTIVATE;
return cp;
}
}
}
}

0 comments on commit 0183dc6

Please sign in to comment.