Winify – Rev 15
?pathlinks?
using System;
using System.Diagnostics;
using System.Drawing;
using System.Speech.Synthesis;
using System.Threading.Tasks;
using System.Windows.Forms;
using Winify.Utilities;
namespace Winify
{
public partial class NotificationForm : Form
{
#region Public Enums, Properties and Fields
public int Index { get; }
#endregion
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
private Point _displayLocation;
private Image _image;
#endregion
#region Constructors, Destructors and Finalizers
public NotificationForm()
{
InitializeComponent();
}
public NotificationForm(int index, Image image, string title, string text, int milliseconds) :
this()
{
Index = index;
_image = image;
pictureBox1.InvokeIfRequired(pictureBox => { pictureBox.Image = image; });
richTextBox2.InvokeIfRequired(richTextBox => { richTextBox.Text = title; });
richTextBox1.InvokeIfRequired(richTextBox => { richTextBox.Text = text; });
Task.Delay(milliseconds).ContinueWith(task =>
this.InvokeIfRequired(form => { form.Close(); }));
}
public NotificationForm(int index, Image image, string title, string text, int milliseconds, string speak) :
this(index, image, title, text, milliseconds)
{
Task.Run(() =>
{
using (var synth = new SpeechSynthesizer())
{
synth.SetOutputToDefaultAudioDevice();
synth.Speak(speak);
}
});
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
if (_image != null)
{
_image.Dispose();
_image = null;
}
components.Dispose();
}
base.Dispose(disposing);
}
#endregion
#region Private Overrides
protected override bool ShowWithoutActivation => true;
protected override void OnLoad(EventArgs e)
{
Location = _displayLocation;
base.OnLoad(e);
}
#endregion
#region Event Handlers
private void PictureBox2_Click(object sender, EventArgs e)
{
this.InvokeIfRequired(form => { form.Close(); });
}
private void NotificationForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (_image != null)
{
_image.Dispose();
_image = null;
}
}
private void RichTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
Process.Start(e.LinkText);
}
private void RichTextBox2_LinkClicked(object sender, LinkClickedEventArgs e)
{
Process.Start(e.LinkText);
}
#endregion
#region Public Methods
public void UpdateLocation(int x, int y)
{
_displayLocation = new Point(x, y);
}
#endregion
}
}
Generated by GNU Enscript 1.6.5.90.