Messagebox.Show()常用参数的讨论

声明:IWin32Window owner   ,  HelpNavigator navigator ,    string keyword

               上面的三个参数类型不是很了解。没有做讨论。

       等以后了解多了,再做补充。。。

 

      下面讨论的一些常用参数,在平时使用,已经绰绰有余了。。。 

 ///

      下面是详细的代码  。

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 对话框_终极版
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("  1  个参数 "
                );
        }

                                      

 

 

 

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" 2 个参数。。 ",
                                 "亮仔提示"
                                 );
        }

                                      


 

 


 

        private void button3_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" 3 个参数。。。 ",
                                " 亮仔提示",
                                MessageBoxButtons.YesNoCancel
                                );
        } 

                                      

 

 

 


        private void button4_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" 4 个参数。。。  ",
                                " 亮仔提示",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning
                                );
        }

                                      

 

 

 

 

 

        private void button5_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" 5 个参数。。 。  ",
                                " 亮仔提示",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button2
                                );
        }

                                      

 

 

 

 

 

        private void button6_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" 6 个参数。。。  ",
                                " 亮仔提示",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button2,
                                MessageBoxOptions.RtlReading      //ServiceNotification//.RightAlign   // 标题向右对齐。
                                );

        }

                                      

 

 

 

 


        private void button7_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" 7 个参数。。帮助菜单不可用。。。。。  ",
                                " 亮仔提示",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button2,
                                MessageBoxOptions.RightAlign,
                                true   // 标题向右对齐。。。。。
                                );

        }

                                      


 

 

 

 

 

        private void button8_Click(object sender, EventArgs e)
        {
            MessageBox.Show(" 7 个参数。帮助菜单    可用。   ",
                                " 亮仔提示",
                                MessageBoxButtons.OKCancel,
                                MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button2,
                               MessageBoxOptions.RightAlign  ,   // 要使用默认风格,此处参数可设为 0    
                                @"C:\Documents and Settings\Administrator\桌面\新建文本文档.txt"
                                );
        }

                                      


    }
}

///

     下面是一些解释。。下面是一些解释。。

     下面是一些解释。。下面是一些解释。。

1.     1个参数。
                 MessageBox.Show(string text);
 //     显示具有指定文本的消息框。
 //
 // 参数:
 //   text:
 //     要在消息框中显示的文本。
 //
 // 返回结果:
 //     System.Windows.Forms.DialogResult 值之一。

2.     2个参数。
                MessageBox.Show(string text, string caption);
//     显示具有指定文本和标题的消息框。
//
// 参数:
//   text:
//     要在消息框中显示的文本。
//
//   caption:
//     要在消息框的标题栏中显示的文本。
//
// 返回结果:
//     System.Windows.Forms.DialogResult 值之一。

3.     3个参数。
             MessageBox.Show(string text, string caption, MessageBoxButtons buttons);
//     显示具有指定文本、标题和按钮的消息框。
//
// 参数:
//   text:
//     要在消息框中显示的文本。
//
//   caption:
//     要在消息框的标题栏中显示的文本。
//
//   buttons:
//     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。
//
// 返回结果:
//     System.Windows.Forms.DialogResult 值之一。
//
// 异常:
//   System.ComponentModel.InvalidEnumArgumentException:
//     指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。
//
//   System.InvalidOperationException:
//     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive
//     属性指定的。

4.     4个参数。
                     MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);
 //     显示具有指定文本、标题、按钮和图标的消息框。
//
// 参数:
//   text:
//     要在消息框中显示的文本。
//
//   caption:
//     要在消息框的标题栏中显示的文本。
//
//   buttons:
//     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。
//
//   icon:
//     System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。
//
// 返回结果:
//     System.Windows.Forms.DialogResult 值之一。
//
// 异常:
//   System.ComponentModel.InvalidEnumArgumentException:
//     指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - 指定的 icon
//     参数不是 System.Windows.Forms.MessageBoxIcon 的成员。
//
//   System.InvalidOperationException:
//     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive
//     属性指定的。
5.     5个参数。
                   MessageBox.Show(string text, string caption, MessageBoxButtons buttons,
                                           MessageBoxIcon icon, MessageBoxDefaultButton defaultButton);
//     显示具有指定文本、标题、按钮、图标和默认按钮的消息框。
//
// 参数:
//   text:
//     要在消息框中显示的文本。
//
//   caption:
//     要在消息框的标题栏中显示的文本。
//
//   buttons:
//     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。
//
//   icon:
//     System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。
//
//   default Button:
//     System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。
//
// 返回结果:
//     System.Windows.Forms.DialogResult 值之一。
//
// 异常:
//   System.ComponentModel.InvalidEnumArgumentException:
//     buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon
//     的成员。- 或 - defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton 的成员。
//
//   System.InvalidOperationException:
//     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive
//     属性指定的。
 6.     6个参数。
                 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon,
                                                         MessageBoxDefaultButton defaultButton, MessageBoxOptions options);
//     显示具有指定文本、标题、按钮、图标、默认按钮和选项的消息框。
//
// 参数:
//   text:
//     要在消息框中显示的文本。
//
//   caption:
//     要在消息框的标题栏中显示的文本。
//
//   buttons:
//     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。
//
//   icon:
//     System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。
//
//   defaultButton:
//     System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。
//
//   options:  //
//     System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入
//     0。
//
// 返回结果:
//     System.Windows.Forms.DialogResult 值之一。
//
// 异常:
//   System.ComponentModel.InvalidEnumArgumentException:
//     buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon
//     的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton
//     的成员。
//
//   System.InvalidOperationException:
//     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive
//     属性指定的。
//
//   System.ArgumentException:
//     options 同时指定了 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和
//     System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons
//     指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。

  
7.     7个参数。
                 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon,
                                         MessageBoxDefaultButton defaultButton, MessageBoxOptions options, bool displayHelpButton);
//     显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和“帮助”按钮的消息框。
//
// 参数:
//   text:
//     要在消息框中显示的文本。
//
//   caption:
//     要在消息框的标题栏中显示的文本。
//
//   buttons:
//     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。
16 //
//   icon:
//     System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。
//
//   defaultButton:
//     System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。
//
//   options:
//     System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入
//     0。
//
//   helpButton:
//     如果显示“帮助”按钮,则为 true;否则为 false。默认为 false。
//
// 返回结果:
//     System.Windows.Forms.DialogResult 值之一。
//
// 异常:
//   System.ComponentModel.InvalidEnumArgumentException:
//     buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon
//     的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton
//     的成员。
//
//   System.InvalidOperationException:
//     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive
//     属性指定的。
//
//   System.ArgumentException:
//     options 同时指定了 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和
//     System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons
//     指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。
8.  (也是 7 个参数)
                      MessageBox.Show(string text, string caption, MessageBoxButtons buttons, 
                                                   MessageBoxIcon icon, MessageBoxDefaultButton defaultButton,
                                                                             MessageBoxOptions options, string helpFilePath);      
//     使用指定的帮助文件显示一个具有指定文本、标题、按钮、图标、默认按钮、选项和“帮助”按钮的消息框。
//
// 参数:
//   text:
//     要在消息框中显示的文本。
//
//   caption:
//     要在消息框的标题栏中显示的文本。
//
//   buttons:
//     System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。
//
//   icon:
//     System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。
//
//   defaultButton:
//     System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。
//
//   options:
//     System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入
//     0。
//
//   helpFilePath:
//     用户单击“帮助”按钮时显示的“帮助”文件的路径和名称。
//
// 返回结果:
//     System.Windows.Forms.DialogResult 值之一。
//
// 异常:
//   System.ComponentModel.InvalidEnumArgumentException:
//     buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon
//     的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton
//     的成员。
//
//   System.InvalidOperationException:
//     试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive
//     属性指定的。
//
//   System.ArgumentException:
//     options 同时指定了 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和
//     System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons
//     指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。


/

  

 

 

作者:Music__Liang
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.--------------------------【保护知识产权,转载请注明出处】

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值