using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace PEP_Tool
{
///
/// Interaktionslogik für XMessageBox.xaml
///
public partial class XMessageBox : Window
{
System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
int timerCount = 0;
public XMessageBox(string Title, string Message, MessageBoxImage image)
{
InitializeComponent();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += Timer_Tick;
timer.Start();
this.Title = Title;
this.Message.Text = Message;
var selectedImage = System.Drawing.SystemIcons.Error;
switch (image)
{
case MessageBoxImage.Error:
selectedImage = System.Drawing.SystemIcons.Error;
break;
case MessageBoxImage.Information:
selectedImage = System.Drawing.SystemIcons.Information;
break;
case MessageBoxImage.Question:
selectedImage = System.Drawing.SystemIcons.Question;
break;
case MessageBoxImage.Warning:
selectedImage = System.Drawing.SystemIcons.Warning;
break;
default:
selectedImage = System.Drawing.SystemIcons.Error;
break;
}
this.Image.Source = ConvertBitmapToImage(selectedImage.ToBitmap());
}
private void Timer_Tick(object sender, EventArgs e)
{
timerCount += 1;
btnBox.Content = $"OK - {(10 - timerCount).ToString()}";
if (timerCount >= 10)
Application.Current.Shutdown();
}
private void Window_Closed(object sender, EventArgs e)
{
Application.Current.Shutdown();
}
///
/// Takes a bitmap and converts it to an image that can be handled by WPF ImageBrush
///
/// A bitmap image
/// The image as a BitmapImage for WPF
public static BitmapImage ConvertBitmapToImage(System.Drawing.Bitmap src)
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
src.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff);
BitmapImage image = new BitmapImage();
image.BeginInit();
ms.Seek(0, System.IO.SeekOrigin.Begin);
image.StreamSource = ms;
image.EndInit();
return image;
}
}
}