Thursday, December 5, 2013

Generic Message Box class

public class MessageBoxHelper
{
/// <summary>/// Shows the message./// </summary>/// <param name="text">The text.</param>public static void ShowMessage(string text){

MessageBox.Show(Application.Current.MainWindow, text);}

/// <summary>/// Shows the message./// </summary>/// <param name="text">The text.</param>/// <param name="caption">The caption.</param>public static void ShowMessage(string text, string caption){

MessageBox.Show(Application.Current.MainWindow, text, caption, MessageBoxButton.OK, MessageBoxImage.Information);}

/// <summary>/// Shows the error message./// </summary>/// <param name="text">The text.</param>/// <param name="caption">The caption.</param>public static void ShowErrorMessage(string text, string caption){

MessageBox.Show(Application.Current.MainWindow, text, caption, MessageBoxButton.OK, MessageBoxImage.Error);}

/// <summary>/// Shows the ok / cancel window./// </summary>/// <param name="text">The text.</param>/// <param name="caption">The caption.</param>public static MessageBoxResult ShowOkCancelWindow(string text, string caption){

return MessageBox.Show(Application.Current.MainWindow, text, caption, MessageBoxButton.OKCancel, MessageBoxImage.Information);}

/// <summary>/// Shows the different button message./// </summary>/// <param name="text">The text.</param>/// <param name="caption">The caption</param>/// <param name="button">The messagebox button type</param>/// <returns></returns>public static MessageBoxResult ShowMessageButton(string text, string caption, MessageBoxButton button){

return MessageBox.Show(Application.Current.MainWindow, text, caption, button, MessageBoxImage.Information);}

/// <summary>/// Shows the error message./// </summary>/// <param name="message">The message.</param>public static void ShowErrorMessage(string message){
ShowErrorMessage(message,
"[Error]");}

/// <summary>/// Shows the yes no window./// </summary>/// <param name="text">The text.</param>/// <param name="caption">The caption.</param>public static MessageBoxResult ShowYesNoWindow(string text, string caption){

return MessageBox.Show(Application.Current.MainWindow, text, caption, MessageBoxButton.YesNo, MessageBoxImage.Question);}

/// <summary>/// Shows the yes no cancel window./// </summary>/// <param name="text">The text.</param>/// <param name="caption">The caption.</param>public static MessageBoxResult ShowYesNoCancelWindow(string text, string caption){

return MessageBox.Show(Application.Current.MainWindow, text, caption, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);}

/// <summary>/// Shows the warning message./// </summary>/// <param name="text">The text.</param>public static void ShowWarningMessage(string text){

//ShowErrorMessage(text, "[Warning]");ShowMessageWithoutParent(text, "[Warning]");}

/// <summary>/// Shows the warningmessage./// </summary>/// <param name="text">The text.</param>/// <param name="caption">The caption.</param>public static void ShowWarningMessage(string text, string caption){

MessageBox.Show(Application.Current.MainWindow, text, caption, MessageBoxButton.OK, MessageBoxImage.Warning);}

/// <summary>/// Shows the error message./// </summary>/// <param name="text">The text.</param>/// <param name="caption">The caption.</param>public static void ShowMessageWithoutParent(string text, string caption){

MessageBox.Show(text, caption, MessageBoxButton.OK, MessageBoxImage.Error);}
}

No comments:

Post a Comment