终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

127 righe
4.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Forms;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Shapes;
  16. namespace BPASmartClient.SCADAControl.Windows
  17. {
  18. /// <summary>
  19. /// MyMessageBox.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class MyMessageBox : Window
  22. {
  23. public MyMessageBox(MessageBoxStyle messageBoxStyle, string msg)
  24. {
  25. InitializeComponent();
  26. this.Width = 393;
  27. btnYes.Click += BtnYes_Click;
  28. btnNo.Click += BtnNo_Click;
  29. btnOk.Click += BtnOk_Click;
  30. this.KeyDown += MyMessageBox_KeyDown;
  31. if (messageBoxStyle == MessageBoxStyle.info)
  32. {
  33. picICO.Source = new BitmapImage(new Uri("../Images/info.png", UriKind.Relative));
  34. //picICO.Image = global::myAlarmSystem.Properties.Resources.info;
  35. this.Title = "提示";
  36. panel1.Visibility = Visibility.Visible;
  37. panel2.Visibility = Visibility.Collapsed;
  38. }
  39. else if (messageBoxStyle == MessageBoxStyle.question)
  40. {
  41. picICO.Source = new BitmapImage(new Uri("../Images/question.png", UriKind.Relative));
  42. //picICO.Image = global::myAlarmSystem.Properties.Resources.question;
  43. this.Title = "询问";
  44. panel1.Visibility = Visibility.Collapsed;
  45. panel2.Visibility = Visibility.Visible;
  46. }
  47. else if (messageBoxStyle == MessageBoxStyle.error)
  48. {
  49. picICO.Source = new BitmapImage(new Uri("../Images/error.png", UriKind.Relative));
  50. //picICO.Image = global::myAlarmSystem.Properties.Resources.error;
  51. this.Title = "错误";
  52. panel1.Visibility = Visibility.Visible;
  53. panel2.Visibility = Visibility.Collapsed;
  54. }
  55. this.labInfo.Text = msg;
  56. SizeF size = TextRenderer.MeasureText(msg, new Font("宋体", 15, System.Drawing.FontStyle.Regular));
  57. int TempWidth = (int)size.Width;
  58. if (TempWidth <= 289) { return; }
  59. this.Height = 150+((int)size.Width/289)*20;
  60. //this.panel1.Width = TempWidth - 20;
  61. //this.panel2.Width = TempWidth - 20;
  62. //btnYes.Width = TempWidth / 2 - 20;
  63. //btnNo.Width = TempWidth / 2 - 20;
  64. }
  65. private void MyMessageBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  66. {
  67. if (e.KeyStates == Keyboard.GetKeyStates(Key.N))
  68. {
  69. BtnNo_Click(null, null);
  70. }
  71. else if (e.KeyStates == Keyboard.GetKeyStates(Key.Y))
  72. {
  73. BtnYes_Click(null, null);
  74. }
  75. else if (e.KeyStates == Keyboard.GetKeyStates(Key.O))
  76. {
  77. BtnOk_Click(null, null);
  78. }
  79. }
  80. private void BtnOk_Click(object sender, RoutedEventArgs e)
  81. {
  82. this.DialogResult = true;
  83. }
  84. private void BtnNo_Click(object sender, RoutedEventArgs e)
  85. {
  86. this.DialogResult = false;
  87. }
  88. private void BtnYes_Click(object sender, RoutedEventArgs e)
  89. {
  90. this.DialogResult = true;
  91. }
  92. private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  93. {
  94. this.Close();
  95. }
  96. }
  97. /// <summary>
  98. /// 消息样式类型
  99. /// </summary>
  100. public enum MessageBoxStyle
  101. {
  102. /// <summary>
  103. /// 通知
  104. /// </summary>
  105. info = 0,
  106. /// <summary>
  107. /// 选择
  108. /// </summary>
  109. question = 1,
  110. /// <summary>
  111. /// 错误
  112. /// </summary>
  113. error = 2
  114. };
  115. }