|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- using System.Windows;
- using System.Windows.Input;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// 消息提示框 .show()
- /// </summary>
- public partial class MessageWindow
- {
- /// <summary>
- /// 提示框
- /// </summary>
- /// <param name="messageType">取消按钮 1不显示2显示</param>
- /// <param name="title">标题</param>
- /// <param name="content"></param>
- public MessageWindow
- (
- int messageType,
- string title,
- string content
- )
- {
- InitializeComponent();
- switch (messageType)
- {
- case 1:
- BorCancel.Visibility = Visibility.Hidden;
- break;
- case 2:
- BorCancel.Visibility = Visibility.Visible;
- break;
- }
- LblTitle.Content = title;
- if (!string.IsNullOrWhiteSpace(content))
- {
- if (content.Length > 143)
- {
- content = content.Substring(0, 140) + "...";
- }
- TbkContent.Text = content;
- }
- else
- {
- TbkContent.Text = "请求失败请重试!";
- }
- }
-
- /// <summary>
- /// 取消
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnCancel_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- }
-
- /// <summary>
- /// 确定
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void BtnOK_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = true;
- }
-
- /// <summary>
- /// 消息提示框
- /// </summary>
- /// <param name="message">消息</param>
- /// <returns></returns>
- public static MessageBoxResult Show(string message)
- {
- string title = "消息提示";
- return Show(message, title);
- }
-
- /// <summary>
- /// 消息提示框
- /// </summary>
- /// <param name="content">消息</param>
- /// <param name="title"></param>
- /// <returns></returns>
- public static MessageBoxResult Show(string content, string title)
- {
- MessageWindow message = new MessageWindow(
- 1,
- title,
- content
- );
- message.ShowDialog();
- return MessageBoxResult.Cancel;
- }
-
- /// <summary>
- /// 消息提示框
- /// </summary>
- /// <param name="title">标题</param>
- /// <param name="content">消息</param>
- /// <param name="messageBox"></param>
- /// <returns></returns>
- public static MessageBoxResult Show
- (
- string content,
- string title,
- MessageBoxButton messageBox
- )
- {
- if (string.IsNullOrWhiteSpace(title))
- {
- title = "消息提示";
- }
- MessageWindow message = new MessageWindow(
- 2,
- title,
- content
- );
- bool? res = message.ShowDialog();
- if (res != null && (bool)res)
- {
- if (messageBox == MessageBoxButton.OKCancel)
- {
- return MessageBoxResult.OK;
- }
- return MessageBoxResult.Yes;
- }
- if (messageBox == MessageBoxButton.OKCancel)
- {
- return MessageBoxResult.Cancel;
- }
- return MessageBoxResult.No;
- }
-
- private static MessageBoxResult Win32ToMessageBoxResult(int value)
- {
- switch (value)
- {
- case 1:
- return MessageBoxResult.OK;
- case 2:
- return MessageBoxResult.Cancel;
- case 6:
- return MessageBoxResult.Yes;
- case 7:
- return MessageBoxResult.No;
- default:
- return MessageBoxResult.No;
- }
- }
-
- private void Window_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.LeftButton == MouseButtonState.Pressed)
- {
- //this.DragMove();
- DragMove();
- }
- }
- }
- }
|