MessageBox


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

MessageBox.Show("Hello World!");

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

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

也可以使用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 theMessageBoxIcon 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.

Icon Member Usage
information Asterisk
Information
Used when showing information to the user.
error Error
Hand
Stop
Used when showing error messages.
warning Exclamation
Warning
Used when showing warning messages.
question Question Used 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 Button1Button2Button3Button4. 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);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值