|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- 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 BPASmartClient.SCADAControl.Windows
- {
- /// <summary>
- /// MyMessageBox.xaml 的交互逻辑
- /// </summary>
- 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();
- }
- }
-
- /// <summary>
- /// 消息样式类型
- /// </summary>
- public enum MessageBoxStyle
- {
- /// <summary>
- /// 通知
- /// </summary>
- info = 0,
- /// <summary>
- /// 选择
- /// </summary>
- question = 1,
- /// <summary>
- /// 错误
- /// </summary>
- error = 2
- };
- }
|