using System.Windows; using System.Windows.Input; namespace XHWK.WKTool { /// /// 消息提示框 .show() /// public partial class MessageWindow : Window { /// /// 提示框 /// /// 取消按钮 1不显示2显示 /// 标题 /// 消息内容 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; default: break; } lblTitle.Content = Title; if (!string.IsNullOrWhiteSpace(Content)) { if (Content.Length > 143) { Content = Content.Substring(0, 140) + "..."; } tbkContent.Text = Content; } else { tbkContent.Text = "错误!"; } } /// /// 取消 /// /// /// private void BtnCancel_Click(object sender, RoutedEventArgs e) { DialogResult = false; } /// /// 确定 /// /// /// private void BtnOK_Click(object sender, RoutedEventArgs e) { DialogResult = true; } /// /// 消息提示框 /// /// 消息 /// public static MessageBoxResult Show(string Message) { string Title = "消息提示"; return Show(Message, Title); } /// /// 消息提示框 /// /// 消息 /// public static MessageBoxResult Show(string Message, string Title) { MessageWindow message = new MessageWindow(1, Title, Message); message.ShowDialog(); return MessageBoxResult.Cancel; } /// /// 消息提示框 /// /// 标题 /// 消息 /// public static MessageBoxResult Show(string Message, string Title, MessageBoxButton messageBox) { if (string.IsNullOrWhiteSpace(Title)) { Title = "消息提示"; } MessageWindow message = new MessageWindow(2, Title, Message); bool? res = message.ShowDialog(); if ((bool)res) { if (messageBox == MessageBoxButton.OKCancel) { return MessageBoxResult.OK; } else { return MessageBoxResult.Yes; } } else { if (messageBox == MessageBoxButton.OKCancel) { return MessageBoxResult.Cancel; } else { 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(); } } } }