-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
} |