天天看点

Wpf--->自定义MessageBox,MessageBox默认的几种样式,MessageBox.Show();的枚举参数默认MessageBox自定义MessageBox

文章目录

  • 默认MessageBox
      • Show
        • 参数解释
      • MessageBoxButton 与MessageBoxImage 枚举类型
  • 自定义MessageBox

默认MessageBox

  1. MessageBox构造函数私有,所以并不能创建实例
  2. MessageBox只有Show方法,并且对Show方法进行了12种重载,

Show

下面是最全的参数API

[SecurityCritical]
public static MessageBoxResult Show(Window owner, string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon);
           

参数解释

  • owner:

    // 一个 System.Windows.Window ,它表示该消息框的所有者窗口。

  • messageBoxText:

    // 一个 System.String ,它指定要显示的文本。

  • caption:

    // 一个 System.String ,它指定要显示的标题栏标题。

  • button:

    // 一个

    System.Windows.MessageBoxButton

    值,该值指定哪个按钮或要显示的按钮。
  • icon:

    // 一个

    System.Windows.MessageBoxImage

    值,该值指定要显示的图标。
  • 返回值:

    // 一个 System.Windows.MessageBoxResult 值,该值指定在用户单击哪个消息框按钮。

MessageBoxButton 与MessageBoxImage 枚举类型

Wpf--->自定义MessageBox,MessageBox默认的几种样式,MessageBox.Show();的枚举参数默认MessageBox自定义MessageBox

自定义MessageBox

  1. 自定义窗口,有过自定义的窗口

    CommonWindow

    示例可以参考,
  2. 添加静态函数Show,由于构造函数私有,MessageBox不能实例化,所以在Show中调用CreateMessageBox在类中new MessageBox(😕还是构造了MessageBox,外界只能通过调用Show来创建MessageBox,所以需要参数重载各式各样的Show)

继续阅读