星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

MessageWindow.xaml.cs 4.5KB

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