/// <summary> /// Displays a message box with OK button /// </summary> /// <param name="message">The message to display</param> /// <param name="title">The title of the message box</param> public static void Show(string message, string title) { using (var msg = new MessageBoxWindow()) { msg.TxtTitle.Text = title; msg.TxtMessage.Text = message; msg.TitleBackgroundPanel.Background = new SolidColorBrush(Color.FromRgb(3, 169, 244)); msg.BorderBrush = new SolidColorBrush(Color.FromRgb(3, 169, 244)); msg.BtnCancel.Visibility = Visibility.Collapsed; msg.BtnOk.Focus(); msg.ShowDialog(); } }
/// <summary> /// Displays a message box with OK button /// </summary> /// <param name="message">The message to display</param> /// <param name="title">The title of the message box</param> /// <param name="IsRTL">(Optional) If true the MessageBox FlowDirection will be RightToLeft</param> public static void Show(string message, string title, bool IsRTL = false) { using (var msg = new MessageBoxWindow()) { msg.Title = title; msg.TxtTitle.Text = title; msg.TxtMessage.Text = message; msg.TitleBackgroundPanel.Background = new SolidColorBrush(Color.FromRgb(3, 169, 244)); msg.BorderBrush = new SolidColorBrush(Color.FromRgb(3, 169, 244)); msg.BtnCancel.Visibility = Visibility.Collapsed; if (IsRTL) { msg.FlowDirection = FlowDirection.RightToLeft; } msg.BtnOk.Focus(); msg.ShowDialog(); } }
/// <summary> /// Shows usual message box. /// </summary> /// <param name="message">The message to display.</param> /// <param name="isCancel">Is cancel button visible?</param> /// <param name="isRightToLeft">(Optional) Is <see cref="FlowDirection"/>=<see cref="FlowDirection.RightToLeft"/>?</param> /// <returns>Message box result. <see cref="MessageBoxResult.Cancel"/> if <see cref="Exception"/> is thrown.</returns> public static MessageBoxResult Show(string message, bool isCancel, bool isRightToLeft = false) { try { using (MessageBoxWindow messageBoxWindow = new MessageBoxWindow()) { messageBoxWindow.MessageTextBlock.Text = message; messageBoxWindow.CancelButton.Visibility = isCancel ? Visibility.Visible : Visibility.Collapsed; messageBoxWindow.FlowDirection = isRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight; messageBoxWindow.OkButton.Focus(); messageBoxWindow.ShowDialog(); return(messageBoxWindow.Result == MessageBoxResult.OK ? MessageBoxResult.OK : MessageBoxResult.Cancel); } } catch (Exception) { return(MessageBoxResult.Cancel); } }
/// <summary> /// Displays an error message box /// </summary> /// <param name="errorMessage">The error error message to display</param> public static void ShowError(string errorMessage) { try { using (var msg = new MessageBoxWindow()) { msg.TxtTitle.Text = MessageBoxTitle; msg.TxtMessage.Text = errorMessage; msg.TitleBackgroundPanel.Background = Brushes.Red; msg.BorderBrush = Brushes.Red; msg.BtnCancel.Visibility = Visibility.Collapsed; msg.BtnOk.Focus(); msg.ShowDialog(); } } catch (Exception) { MessageBox.Show(errorMessage); } }
/// <summary> /// Displays a warning message box /// </summary> /// <param name="warningMessage">The warning message to display</param> /// <param name="warningTitle">The title of the error message box</param> public static void ShowWarning(string warningMessage, string warningTitle) { try { using (var msg = new MessageBoxWindow()) { msg.Title = warningTitle; msg.TxtTitle.Text = warningTitle; msg.TxtMessage.Text = warningMessage; msg.TitleBackgroundPanel.Background = Brushes.Orange; msg.BorderBrush = Brushes.Orange; msg.BtnCancel.Visibility = Visibility.Collapsed; msg.BtnOk.Focus(); msg.ShowDialog(); } } catch (Exception) { MessageBox.Show(warningMessage, warningTitle); } }
/// <summary> /// Displays a message box with a cancel button /// </summary> /// <param name="message">The message to display</param> /// <returns>Message box Result OK or CANCEL</returns> public static MessageBoxResult ShowWithCancel(string message) { try { using (var msg = new MessageBoxWindow()) { msg.TxtTitle.Text = MessageBoxTitle; msg.TxtMessage.Text = message; msg.TitleBackgroundPanel.Background = new SolidColorBrush(Color.FromRgb(3, 169, 244)); msg.BorderBrush = new SolidColorBrush(Color.FromRgb(3, 169, 244)); msg.BtnOk.Focus(); msg.ShowDialog(); return(msg.Result == MessageBoxResult.OK ? MessageBoxResult.OK : MessageBoxResult.Cancel); } } catch (Exception) { MessageBox.Show(message); return(MessageBoxResult.Cancel); } }