using System;
using System.Collections.Generic;
using System.Drawing;
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.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace BeDesignerSCADA.View
{
///
/// MyMessageBox.xaml 的交互逻辑
///
public partial class MyMessageBox : Window
{
public MyMessageBox(MessageBoxStyle messageBoxStyle, string msg)
{
InitializeComponent();
this.Width = 393;
btnYes.Click += BtnYes_Click;
btnNo.Click += BtnNo_Click;
btnOk.Click += BtnOk_Click;
this.KeyDown += MyMessageBox_KeyDown;
if (messageBoxStyle == MessageBoxStyle.info)
{
picICO.Source = new BitmapImage(new Uri("../Images/info.png", UriKind.Relative));
//picICO.Image = global::myAlarmSystem.Properties.Resources.info;
this.Title = "提示";
panel1.Visibility = Visibility.Visible;
panel2.Visibility = Visibility.Collapsed;
}
else if (messageBoxStyle == MessageBoxStyle.question)
{
picICO.Source = new BitmapImage(new Uri("../Images/question.png", UriKind.Relative));
//picICO.Image = global::myAlarmSystem.Properties.Resources.question;
this.Title = "询问";
panel1.Visibility = Visibility.Collapsed;
panel2.Visibility = Visibility.Visible;
}
else if (messageBoxStyle == MessageBoxStyle.error)
{
picICO.Source = new BitmapImage(new Uri("../Images/error.png", UriKind.Relative));
//picICO.Image = global::myAlarmSystem.Properties.Resources.error;
this.Title = "错误";
panel1.Visibility = Visibility.Visible;
panel2.Visibility = Visibility.Collapsed;
}
this.labInfo.Text = msg;
SizeF size = TextRenderer.MeasureText(msg, new Font("宋体", 15, System.Drawing.FontStyle.Regular));
int TempWidth = (int)size.Width;
if (TempWidth <= 289) { return; }
this.Height = 150 + ((int)size.Width / 289) * 20;
//this.panel1.Width = TempWidth - 20;
//this.panel2.Width = TempWidth - 20;
//btnYes.Width = TempWidth / 2 - 20;
//btnNo.Width = TempWidth / 2 - 20;
}
private void MyMessageBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.KeyStates == Keyboard.GetKeyStates(Key.N))
{
BtnNo_Click(null, null);
}
else if (e.KeyStates == Keyboard.GetKeyStates(Key.Y))
{
BtnYes_Click(null, null);
}
else if (e.KeyStates == Keyboard.GetKeyStates(Key.O))
{
BtnOk_Click(null, null);
}
}
private void BtnOk_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void BtnNo_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
}
private void BtnYes_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
}
private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.Close();
}
}
///
/// 消息样式类型
///
public enum MessageBoxStyle
{
///
/// 通知
///
info = 0,
///
/// 选择
///
question = 1,
///
/// 错误
///
error = 2
};
}