VBnet MSGBOX 转发

VB.Net中MsgBox函数的使用方法

http://www.lob.cn/jq/kfjq/570.shtml

VB.Net中MsgBox函数的使用方法
作者:佚名 来源:乐博网收集 更新时间:2007-11-24

MsgBox: Prompts a dialog Box that displays a message.

Examples:

MsgBox("Thank You for the Help!")

information from the MSDN:MsgBox Function

Parameters

Prompt
required. Stringexpression displayed as the message in the dialog Box. The maximum length of Promptis approximately 1024 characters,depending on the width of the characters used. If Promptconsists of more than one line,you can separate the lines using a carriage return character ( Chr(13 )),a lineFeed character ( Chr(10 )),or a carriage return/lineFeed character combination ( Chr(13 )& Chr(10 )) between each line.
Buttons
Optional. Numeric expression that is the sum of values specifying the number and type of buttons to display,the icon style to use,the identity of the default button,and the modality of the message Box. If you omit Buttons,the default value is zero.
Title
Optional. Stringexpression displayed in the title bar of the dialog Box. If you omit Title,the application name is placed in the title bar.

Settings

TheMsgBoxStyleenumeration values are listed in the following table.

Enumeration Value Description
OKOnly
0
displays OK button only.
OKCancel
1
displays OK and Cancel buttons.
AbortRetryIgnore
2
displays Abort,Retry,and Ignore buttons.
YesNoCancel
3
displays Yes,No,and Cancel buttons.
YesNo
4
displays Yes and No buttons.
RetryCancel
5
displays Retry and Cancel buttons.
Critical
16
displays Critical Message icon.
Question
32
displays Warning Query icon.
Exclamation
48
displays Warning Message icon.
information
64
displays information Message icon.
DefaultButton1
0
First button is default.
DefaultButton2
256
Second button is default.
DefaultButton3
512
Third button is default.
ApplicationModal
0
Application is modal. The user must respond to the message Box before continuing work in the current application.
SystemModal
4096
System is modal. All applications are suspended until the user responds to the message Box.
MsgBoxSetForeground
65536
Specifies the message Box window as the foreground window.
MsgBoxRight
524288
Text is right-aligned.
MsgBoxRtlReading
1048576
Specifies text should appear as right-to-left reading on Hebrew and arabic systems.

The first group of values (0–5) describes the number and type of buttons displayed in the dialog Box; the second group (16,32,48,64) describes the icon style; the third group (0,256,512) determines which button is the default; the fourth group (0,4096) determines the modality of the message Box,and the fifth group specifies whether or not the message Box window is the foreground window,along with the alignment and direction of the text. When adding numbers to create a final value for theButtonsargument,use only one number from each group.

Return Values

Constant
Value
OK
1
Cancel
2
Abort
3
Retry
4
Ignore
5
Yes
6
No
7

Exceptions/Errors

Exception type
Error number Condition
ArgumentException
5
Promptis not aStringexpression,orTitleis invalid.
InvalidOperationException
5
Process is not running in User Interactive mode.
InvalidEnumArgumentException
5
One or more parameters not a member ofMsgBoxResultorMsgBoxStyleenumerations.

Remarks

If the dialog Box displays aCancelbutton,pressing the ESC key has the same effect as clickingCancel. If the dialog Box contains aHelpbutton,context-sensitive Help is provided for the dialog Box. However,no value is returned until one of the other buttons is clicked.

NoteTo specify more than the first argument,you must use the MsgBoxfunction in an expression. If you omit any positional arguments,you must retain the corresponding comma delimiter.

Example

This example uses theMsgBoxfunction to display a critical-error message in a dialog Box with Yes and No buttons. The No button is specified as the default response. This is done by combining theMsgBoxconstant values into one numeric expression. In this case,adding 4 (the Yes/No button combination) and 16 (the Critical Message window) and 256 (the second button as default button) gives a total of 276. The value returned by theMsgBoxfunction depends on the button chosen by the user: Yes returns a value of 6; No returns a value of 7.

Dim msg As String
Dim title As String
Dim style As MsgBoxStyle
Dim response As MsgBoxResult
msg = "Do you want to continue?"   ' Define message.
style = MsgBoxStyle.DefaultButton2 Or _
   MsgBoxStyle.Critical Or MsgBoxStyle.YesNo
title = "MsgBox Demonstration"   ' Define title.
' display message.
response = msg,style,title  ' or MsgBox(msg,MsgBoxStyle.YesNo,title)
If response = MsgBoxResult.Yes Then   ' User chose Yes.
   ' Perform some action.
Else
   ' Perform some other action.
End IfMsgBox()

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...