public Notifier(NotifierOptions newOptions, string notifierTitle, string notifierDescription, string notifierCategory, Image notifierImage = null) { InitializeComponent(); startTickCount = Environment.TickCount; title = notifierTitle; description = notifierDescription; image = notifierImage; category = notifierCategory; options = newOptions; if (!options.enabled) { this.Close(); } this.Top = Screen.PrimaryScreen.WorkingArea.Bottom; this.Left = Screen.PrimaryScreen.WorkingArea.Right - this.Width; Color magicPink = Color.FromArgb(255, 0, 255); this.BackColor = magicPink; this.TransparencyKey = magicPink; heightToRiseTo = previousForm == null ? Screen.PrimaryScreen.WorkingArea.Bottom : previousForm.Top; int textStartingPoint = (image == null || !options.showImage) ? 10 : 300; int descriptionStartingHeight = title == null ? 10 : TextRenderer.MeasureText(title, options.titleFont).Height + 10; int previousHeight = 0, previousWidth = 0; while (TextRenderer.MeasureText(title, options.titleFont).Width + textStartingPoint > this.Width || this.Width - textStartingPoint < 200) { this.Width += 10; this.Left -= 10; if (this.Width == previousWidth) { //We've hit the maximum allowed size for a window! break; } previousWidth = this.Width; } int textWidth = this.Width - textStartingPoint; string wrappedDescrption = WordWrap(description, textWidth, options.descriptionFont); while (TextRenderer.MeasureText(wrappedDescrption, options.descriptionFont).Height + TextRenderer.MeasureText(category, options.descriptionFont).Height + descriptionStartingHeight > this.Height) { this.Height += 10; if (this.Height == previousHeight) { break; } previousHeight = this.Height; } previousForm = this; }
private void Notifier_FormClosed(object sender, FormClosedEventArgs e) { if (previousForm == this) { previousForm = null; } }
public static Notifier ShowNotification(string title, string description, string category = "", Image image = null, Form parent = null) { Notifier newNotifier = null; Action showNotification = (() => { newNotifier = new Notifier(Notifier.DefaultOptions, title, description, category, image); newNotifier.parentForm = parent; newNotifier.Visible = true; }); if (parent != null) { parent.Invoke(showNotification); } else { showNotification(); } return newNotifier; }