MessageBox 类,不一样的感觉

我们在使用messagebox时,通常采用下面的最简化的方式:

MessageBox.Show("Hello World!");

2011062417155875.jpg

当我们为messagebox添加标题时,可以这样做:

MessageBox.Show("Hello World!", "A Message");

2011062417175065.jpg

也可以使用System.Windows.Forms.MessageBoxButtons enumeration为messagebox添加按钮。

MessageBox.Show("Hello World!", "A Message", MessageBoxButtons.OKCancel);

Message Box

The table below shows the members of the MessageBoxButtons enumeration.

MemberButtons Shown
AbortRetryIgnoreAbort, Retry, Ignore
OKOK
OKCancelOK, Cancel
RetryCancelRetry, Cancel
YesNoYes, No
YesNoCancelYes, No, Cancel

You can also add an icon for your message box to further imply the purpose of the message. You do this by using the members of the MessageBoxIcon enumeration.

MessageBox.Show("Hello World!", "A Message", 
   MessageBoxButtons.OK, MessageBoxIcon.Information);

Message Box

The table below shows the different icons that you can use for your message box.

IconMemberUsage
informationAsterisk
Information
Used when showing information to the user.
errorError
Hand
Stop
Used when showing error messages.
warningExclamation
Warning
Used when showing warning messages.
questionQuestionUsed when asking a question to the user.

You can use the MessageBoxIcon.None to indicate that the message box will have no icon.

The MessageBoxDefaultButton enumeration tells which of the button is the default, that is, the one that is pressed when the enter key in the keyboard is pushed. It has only 4 member which are Button1, Button2, Button3, Button4. For example, in a message box that has an OK and a Cancel buttons, using MessageBoxDefaultButton.Button1 will make the OK button as the default. When the message box is shown and you pressed Enter in the keyboard, the OK button is pressed.

MessageBox.Show("Hello World!", "A Message",
   MessageBoxButtons.OKCancel, MessageBoxDefaultButton.Button1);

转载于:https://www.cnblogs.com/irving314/archive/2011/06/24/messagebox.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值