Toasts – Rev 3
?pathlinks?
using System;
using System.Drawing;
using System.IO;
using System.Media;
using System.Windows.Forms;
using Toasts;
namespace Test
{
public partial class Test : Form
{
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
private bool _initialLoad = true;
#endregion
#region Constructors, Destructors and Finalizers
public Test()
{
InitializeComponent();
PopulateComboBoxes();
}
#endregion
#region Event Handlers
private void ButtonShowNotification_Click(object sender, EventArgs e)
{
ShowNotification();
}
private void ComboBoxSound_SelectedIndexChanged(object sender, EventArgs e)
{
if (!_initialLoad) PlayNotificationSound(comboBoxSound.Text);
}
#endregion
#region Private Methods
private void PopulateComboBoxes()
{
foreach (FormAnimator.AnimationMethod method in Enum.GetValues(typeof(FormAnimator.AnimationMethod)))
comboBoxAnimation.Items.Add(method.ToString());
comboBoxAnimation.SelectedIndex = 2;
foreach (FormAnimator.AnimationDirection direction in Enum.GetValues(
typeof(FormAnimator.AnimationDirection)))
comboBoxAnimationDirection.Items.Add(direction.ToString());
comboBoxAnimationDirection.SelectedIndex = 3;
var soundsFolder = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sounds"));
foreach (var file in soundsFolder.GetFiles())
comboBoxSound.Items.Add(Path.GetFileNameWithoutExtension(file.FullName));
comboBoxSound.SelectedIndex = 5;
_initialLoad = false;
comboBoxDuration.SelectedIndex = 0;
}
private void ShowNotification()
{
int duration;
int.TryParse(comboBoxDuration.SelectedItem.ToString(), out duration);
if (duration <= 0) duration = -1;
var animationMethod = FormAnimator.AnimationMethod.Slide;
foreach (FormAnimator.AnimationMethod method in Enum.GetValues(typeof(FormAnimator.AnimationMethod)))
if (Equals(method.ToString(), comboBoxAnimation.SelectedItem))
{
animationMethod = method;
break;
}
var animationDirection = FormAnimator.AnimationDirection.Up;
foreach (FormAnimator.AnimationDirection direction in Enum.GetValues(
typeof(FormAnimator.AnimationDirection)))
if (Equals(direction.ToString(), comboBoxAnimationDirection.SelectedItem))
{
animationDirection = direction;
break;
}
var imagesFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Images");
var backgroundFile = Path.Combine(imagesFolder, "background.png");
var background = new Bitmap(backgroundFile);
var logoFile = Path.Combine(imagesFolder, "was.png");
var logo = new Bitmap(logoFile);
var toastNotification = new ToastForm(textBoxTitle.Text, textBoxBody.Text, duration,
logo, background, animationMethod, animationDirection);
PlayNotificationSound(comboBoxSound.Text);
toastNotification.Show();
}
private static void PlayNotificationSound(string sound)
{
var soundsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sounds");
var soundFile = Path.Combine(soundsFolder, sound + ".wav");
using (var player = new SoundPlayer(soundFile))
{
player.Play();
}
}
#endregion
}
}
Generated by GNU Enscript 1.6.5.90.