PEPTool/AV-ToolV3/XMessageBox.xaml.cs
2025-10-08 10:11:18 +02:00

91 lines
2.9 KiB
C#

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
{
/// <summary>
/// Interaktionslogik für XMessageBox.xaml
/// </summary>
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();
}
/// <summary>
/// Takes a bitmap and converts it to an image that can be handled by WPF ImageBrush
/// </summary>
/// <param name="src">A bitmap image</param>
/// <returns>The image as a BitmapImage for WPF</returns>
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;
}
}
}