zoukankan      html  css  js  c++  java
  • Messagebox.Show()常用参数的讨论

    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 SettingsAdministrator桌面新建文本文档.txt"
                                    );
            }

                                          


        }
    }

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

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

    复制代码
     1 1.     1个参数。
    2 MessageBox.Show(string text);
    3 // 显示具有指定文本的消息框。
    4 //
    5 // 参数:
    6 // text:
    7 // 要在消息框中显示的文本。
    8 //
    9 // 返回结果:
    10 // System.Windows.Forms.DialogResult 值之一。
    复制代码
    复制代码
     1 2.     2个参数。
    2 MessageBox.Show(string text, string caption);
    3 // 显示具有指定文本和标题的消息框。
    4 //
    5 // 参数:
    6 // text:
    7 // 要在消息框中显示的文本。
    8 //
    9 // caption:
    10 // 要在消息框的标题栏中显示的文本。
    11 //
    12 // 返回结果:
    13 // System.Windows.Forms.DialogResult 值之一。
    复制代码
    复制代码
     1 3.     3个参数。
    2 MessageBox.Show(string text, string caption, MessageBoxButtons buttons);
    3 // 显示具有指定文本、标题和按钮的消息框。
    4 //
    5 // 参数:
    6 // text:
    7 // 要在消息框中显示的文本。
    8 //
    9 // caption:
    10 // 要在消息框的标题栏中显示的文本。
    11 //
    12 // buttons:
    13 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。
    14 //
    15 // 返回结果:
    16 // System.Windows.Forms.DialogResult 值之一。
    17 //
    18 // 异常:
    19 // System.ComponentModel.InvalidEnumArgumentException:
    20 // 指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。
    21 //
    22 // System.InvalidOperationException:
    23 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive
    24 // 属性指定的。
    复制代码

      

    复制代码
     1 4.     4个参数。
    2 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon);
    3 // 显示具有指定文本、标题、按钮和图标的消息框。
    4 //
    5 // 参数:
    6 // text:
    7 // 要在消息框中显示的文本。
    8 //
    9 // caption:
    10 // 要在消息框的标题栏中显示的文本。
    11 //
    12 // buttons:
    13 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。
    14 //
    15 // icon:
    16 // System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。
    17 //
    18 // 返回结果:
    19 // System.Windows.Forms.DialogResult 值之一。
    20 //
    21 // 异常:
    22 // System.ComponentModel.InvalidEnumArgumentException:
    23 // 指定的 buttons 参数不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - 指定的 icon
    24 // 参数不是 System.Windows.Forms.MessageBoxIcon 的成员。
    25 //
    26 // System.InvalidOperationException:
    27 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive
    28 // 属性指定的。
    复制代码

             
     

    复制代码
     1       
    2 5. 5个参数。
    3 MessageBox.Show(string text, string caption, MessageBoxButtons buttons,
    4 MessageBoxIcon icon, MessageBoxDefaultButton defaultButton);
    5 // 显示具有指定文本、标题、按钮、图标和默认按钮的消息框。
    6 //
    7 // 参数:
    8 // text:
    9 // 要在消息框中显示的文本。
    10 //
    11 // caption:
    12 // 要在消息框的标题栏中显示的文本。
    13 //
    14 // buttons:
    15 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。
    16 //
    17 // icon:
    18 // System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。
    19 //
    20 // default Button:
    21 // System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。
    22 //
    23 // 返回结果:
    24 // System.Windows.Forms.DialogResult 值之一。
    25 //
    26 // 异常:
    27 // System.ComponentModel.InvalidEnumArgumentException:
    28 // buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon
    29 // 的成员。- 或 - defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton 的成员。
    30 //
    31 // System.InvalidOperationException:
    32 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive
    33 // 属性指定的。
    复制代码

      

    复制代码
     1 6.     6个参数。
    2 MessageBox.Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon,
    3 MessageBoxDefaultButton defaultButton, MessageBoxOptions options);
    4 // 显示具有指定文本、标题、按钮、图标、默认按钮和选项的消息框。
    5 //
    6 // 参数:
    7 // text:
    8 // 要在消息框中显示的文本。
    9 //
    10 // caption:
    11 // 要在消息框的标题栏中显示的文本。
    12 //
    13 // buttons:
    14 // System.Windows.Forms.MessageBoxButtons 值之一,可指定在消息框中显示哪些按钮。
    15 //
    16 // icon:
    17 // System.Windows.Forms.MessageBoxIcon 值之一,它指定在消息框中显示哪个图标。
    18 //
    19 // defaultButton:
    20 // System.Windows.Forms.MessageBoxDefaultButton 值之一,可指定消息框中的默认按钮。
    21 //
    22 // options: //
    23 // System.Windows.Forms.MessageBoxOptions 值之一,可指定将对消息框使用哪些显示和关联选项。若要使用默认值,请传入
    24 // 0。
    25 //
    26 // 返回结果:
    27 // System.Windows.Forms.DialogResult 值之一。
    28 //
    29 // 异常:
    30 // System.ComponentModel.InvalidEnumArgumentException:
    31 // buttons 不是 System.Windows.Forms.MessageBoxButtons 的成员。- 或 - icon 不是 System.Windows.Forms.MessageBoxIcon
    32 // 的成员。- 或 - 指定的 defaultButton 不是 System.Windows.Forms.MessageBoxDefaultButton
    33 // 的成员。
    34 //
    35 // System.InvalidOperationException:
    36 // 试图在运行模式不是用户交互模式的进程中显示 System.Windows.Forms.MessageBox。这是由 System.Windows.Forms.SystemInformation.UserInteractive
    37 // 属性指定的。
    38 //
    39 // System.ArgumentException:
    40 // options 同时指定了 System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly 和
    41 // System.Windows.Forms.MessageBoxOptions.ServiceNotification。- 或 - buttons
    42 // 指定了无效的 System.Windows.Forms.MessageBoxButtons 组合。
    复制代码
    7个参数

          

     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

    刚好用到MessageBox  ,所以就在网上查着学习了一下。

    MessageBox.Show(<字符串> Text, <字符串> Title, <整型> nType,MessageBoxIcon);

    它的格式就是上面这个,

    第一个参数是 String 类型,表示提示框里面的 内容;

    第二个参数是String 类型,表示提示框的 标题;

    第三个参数是整数类型,表示消息框的  类型  ,一般的都使用系统提供的几种类型;

    第四个参数是提示框的 图标,比如说警告、提示、问题等等。

    四个参数可以只填一个、或者两个、或者3个。。。如下图,

    代码分别是:
    ————————————————

    它的类型也有多种选择:

    MessageBox.Show("消息内容", "返回值 确定1",MessageBoxButtons.OK,MessageBoxIcon.Question);

    MessageBox.Show("消息内容",, "返回值 确定1 取消2",MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);

    MessageBox.Show("消息内容", "返回值 终止3 重试4 忽略5",MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);

    MessageBox.Show("消息内容", "返回值 是6 否7 取消2",MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);

    MessageBox.Show("消息内容", "返回值 是6 否7",MessageBoxButtons.YesNo, MessageBoxIcon.Hand);

    MessageBox.Show("消息内容", "返回值 重试4 取消2",MessageBoxButtons.RetryCancel, MessageBoxIcon.Information);
    ————————————————

    在这里我用到的是第二种,进行判断的作用。

    string rmname = txb_rename.Text.Trim();
    string msg = "确定需要删除 "+rmname+" 吗?";

    if((int)MessageBox.Show(msg,"提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation)!=1){return;}
    它的几种图标样式:

    MessageBoxIcon.Question

    MessageBoxIcon.Asterisk

    MessageBoxIcon.Information

    MessageBoxIcon.Error

    MessageBoxIcon.Stop

    MessageBoxIcon.Hand

    MessageBoxIcon.Exclamation

    MessageBoxIcon.Warning

  • 相关阅读:
    聊聊WS-Federation
    用双十一的故事串起碎片的网络协议(上)
    责任链模式的使用-Netty ChannelPipeline和Mina IoFilterChain分析
    最小化局部边际的合并聚类算法(中篇)
    最小化局部边际的合并聚类算法(上篇)
    UVaLive 7371 Triangle (水题,判矩形)
    UVaLive 7372 Excellence (水题,贪心)
    POJ 3312 Mahershalalhashbaz, Nebuchadnezzar, and Billy Bob Benjamin Go to the Regionals (水题,贪心)
    UVa 1252 Twenty Questions (状压DP+记忆化搜索)
    UVa 10817 Headmaster's Headache (状压DP+记忆化搜索)
  • 原文地址:https://www.cnblogs.com/mjgw/p/12588100.html
Copyright © 2011-2022 走看看