MessageBox.Show()使用小结

在程序调试/运行过程中,出于需要我们需要显示出一些信息,这时使用MessageBox.Show()是一个比较不错的选择。MessageBox类的静态方法Show有21个重载函数:

public static DialogResult Show(string text);
public static DialogResult Show(IWin32Window owner, string text);
public static DialogResult Show(string text, string caption);
public static DialogResult Show(IWin32Window owner, string text, string caption);
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons);
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons);
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton);
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton);
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options);
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options);
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, bool displayHelpButton);
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath);
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath);
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator navigator);
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, string keyword);
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator navigator);
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, string keyword);
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator navigator, object param);
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, string helpFilePath, HelpNavigator navigator, object param);

几个相关的枚举:

public enum MessageBoxButtons
{
    OK = 0,
    OKCancel = 1,
    AbortRetryIgnore = 2,
    YesNoCancel = 3,
    YesNo = 4,
    RetryCancel = 5,
}

public enum MessageBoxIcon
{
    None = 0,
    Error = 16,
    Hand = 16,
    Stop = 16,
    Question = 32,
    Exclamation = 48,
    Warning = 48,
    Information = 64,
    Asterisk = 64,
}

public enum DialogResult
{
    None = 0,
    OK = 1,
    Cancel = 2,
    Abort = 3,
    Retry = 4,
    Ignore = 5,
    Yes = 6,
    No = 7,
}

使用示例:

//标题为"木子屋"
MessageBox.Show("URL:http://www.mzwu.com/", "木子屋");
//标题为"木子屋",带"是/否"两个按钮
MessageBox.Show("URL:http://www.mzwu.com/", "木子屋",MessageBoxButtons.YesNo);
//标题为"木子屋",带"是/否/取消"三个按钮,显示一个信息类型的图标
MessageBox.Show("URL:http://www.mzwu.com/", "木子屋", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
//标题为"木子屋",带"是/否/取消"三个按钮,显示一个警告类型的图标,默认选中第二个按钮
MessageBox.Show("URL:http://www.mzwu.com/", "木子屋", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning,MessageBoxDefaultButton.Button2);


评论: 0 | 引用: 0 | 查看次数: 7369
发表评论
登录后再发表评论!