星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MessageWindow.xaml.cs 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace XHWK.WKTool
  15. {
  16. /// <summary>
  17. /// MessageWindow.xaml 的交互逻辑
  18. /// </summary>
  19. public partial class MessageWindow : Window
  20. {
  21. /// <summary>
  22. /// 提示框
  23. /// </summary>
  24. /// <param name="MessageType">取消按钮 1不显示2显示</param>
  25. /// <param name="Title">标题</param>
  26. /// <param name="content">消息内容</param>
  27. public MessageWindow(int MessageType,string Title,string Content)
  28. {
  29. InitializeComponent();
  30. switch (MessageType)
  31. {
  32. case 1:
  33. borCancel.Visibility = Visibility.Hidden;
  34. break;
  35. case 2:
  36. borCancel.Visibility = Visibility.Visible;
  37. break;
  38. default:
  39. break;
  40. }
  41. lblTitle.Content = Title;
  42. if (string.IsNullOrWhiteSpace(Content))
  43. {
  44. if(Content.Length>143)
  45. {
  46. Content = Content.Substring(0, 140) + "...";
  47. }
  48. tbkContent.Text = Content;
  49. }
  50. else
  51. {
  52. tbkContent.Text = "错误!";
  53. }
  54. }
  55. /// <summary>
  56. /// 取消
  57. /// </summary>
  58. /// <param name="sender"></param>
  59. /// <param name="e"></param>
  60. private void BtnCancel_Click(object sender, RoutedEventArgs e)
  61. {
  62. DialogResult = false;
  63. }
  64. /// <summary>
  65. /// 确定
  66. /// </summary>
  67. /// <param name="sender"></param>
  68. /// <param name="e"></param>
  69. private void BtnOK_Click(object sender, RoutedEventArgs e)
  70. {
  71. DialogResult = true;
  72. }
  73. /// <summary>
  74. /// 消息提示框
  75. /// </summary>
  76. /// <param name="Message">消息</param>
  77. /// <returns></returns>
  78. public static MessageBoxResult Show(string Message)
  79. {
  80. string Title = "消息提示";
  81. return Show(Message, Title);
  82. }
  83. /// <summary>
  84. /// 消息提示框
  85. /// </summary>
  86. /// <param name="Message">消息</param>
  87. /// <returns></returns>
  88. public static MessageBoxResult Show(string Message,string Title)
  89. {
  90. MessageWindow message = new MessageWindow(1, Title, Message);
  91. message.ShowDialog();
  92. return MessageBoxResult.Cancel;
  93. }
  94. /// <summary>
  95. /// 消息提示框
  96. /// </summary>
  97. /// <param name="Title">标题</param>
  98. /// <param name="Message">消息</param>
  99. /// <returns></returns>
  100. public static MessageBoxResult Show(string Message,string Title, MessageBoxButton messageBox)
  101. {
  102. if (string.IsNullOrWhiteSpace(Title))
  103. {
  104. Title = "消息提示";
  105. }
  106. MessageWindow message = new MessageWindow(2,Title,Message);
  107. bool? res= message.ShowDialog();
  108. if ((bool)res)
  109. {
  110. if (messageBox == MessageBoxButton.OKCancel)
  111. {
  112. return MessageBoxResult.OK;
  113. }
  114. else
  115. {
  116. return MessageBoxResult.Yes;
  117. }
  118. }
  119. else
  120. {
  121. if (messageBox == MessageBoxButton.OKCancel)
  122. {
  123. return MessageBoxResult.Cancel;
  124. }
  125. else
  126. {
  127. return MessageBoxResult.No;
  128. }
  129. }
  130. }
  131. private static MessageBoxResult Win32ToMessageBoxResult(int value)
  132. {
  133. switch (value)
  134. {
  135. case 1:
  136. return MessageBoxResult.OK;
  137. case 2:
  138. return MessageBoxResult.Cancel;
  139. case 6:
  140. return MessageBoxResult.Yes;
  141. case 7:
  142. return MessageBoxResult.No;
  143. default:
  144. return MessageBoxResult.No;
  145. }
  146. }
  147. private void Window_MouseMove(object sender, MouseEventArgs e)
  148. {
  149. if (e.LeftButton == MouseButtonState.Pressed)
  150. {
  151. //this.DragMove();
  152. this.DragMove();
  153. }
  154. }
  155. }
  156. }