Interaction.MsgBox(Object, MsgBoxStyle, Object) 메서드
정의
대화 상자에 메시지를 표시하고 사용자가 단추를 클릭할 때까지 대기한 다음 클릭된 단추를 나타내는 정수를 반환합니다.Displays a message in a dialog box, waits for the user to click a button, and then returns an integer indicating which button the user clicked.
public static Microsoft.VisualBasic.MsgBoxResult MsgBox (object Prompt, Microsoft.VisualBasic.MsgBoxStyle Buttons = Microsoft.VisualBasic.MsgBoxStyle.OkOnly, object? Title = default);
public static Microsoft.VisualBasic.MsgBoxResult MsgBox (object Prompt, Microsoft.VisualBasic.MsgBoxStyle Buttons = Microsoft.VisualBasic.MsgBoxStyle.ApplicationModal, object Title = default);
static member MsgBox : obj * Microsoft.VisualBasic.MsgBoxStyle * obj -> Microsoft.VisualBasic.MsgBoxResult
Public Function MsgBox (Prompt As Object, Optional Buttons As MsgBoxStyle = Microsoft.VisualBasic.MsgBoxStyle.OkOnly, Optional Title As Object = Nothing) As MsgBoxResult
Public Function MsgBox (Prompt As Object, Optional Buttons As MsgBoxStyle = Microsoft.VisualBasic.MsgBoxStyle.ApplicationModal, Optional Title As Object = Nothing) As MsgBoxResult
매개 변수
- Prompt
- Object
필수 요소.Required. 대화 상자에서 메시지로 표시되는 String
식입니다.String
expression displayed as the message in the dialog box. Prompt
의 최대 길이는 대략 1024자이며 사용되는 문자의 너비에 따라 달라집니다.The maximum length of Prompt
is approximately 1024 characters, depending on the width of the characters used. Prompt
가 두 줄 이상으로 구성되는 경우 캐리지 리턴 문자(Chr(
13)
), 줄 바꿈 문자(Chr(
10)
) 또는 각 줄 사이에 캐리지 리턴/줄 바꿈 조합(Chr(
13)
& Chr(
10)
)을 사용하여 줄을 구분할 수 있습니다.If Prompt
consists of more than one line, you can separate the lines using a carriage return character (Chr(
13)
), a line feed character (Chr(
10)
), or a carriage return/linefeed character combination (Chr(
13)
& Chr(
10)
) between each line.
- Buttons
- MsgBoxStyle
선택 사항입니다.Optional. 표시할 단추의 수와 형식, 사용할 아이콘 스타일, 기본 단추의 ID 및 메시지 상자의 모달을 지정하는 값의 합을 나타내는 숫자 식입니다.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. Buttons
를 생략한 경우 기본값은 0입니다.If you omit Buttons
, the default value is zero.
- Title
- Object
선택 사항입니다.Optional. 대화 상자의 제목 표시줄에 표시되는 String
식입니다.String
expression displayed in the title bar of the dialog box. Title
을 생략하면 애플리케이션 이름이 제목 표시줄에 나타납니다.If you omit Title
, the application name is placed in the title bar.
반환
다음 값 중 하나입니다.One of the following values:
상수Constant | 값Value |
---|---|
OK | 11 |
Cancel | 22 |
Abort | 33 |
Retry | 44 |
Ignore | 55 |
Yes | 66 |
No | 77 |
예외
Prompt
가 String
식이 아니거나 Title
이 올바르지 않습니다.Prompt
is not a String
expression, or Title
is invalid.
프로세스가 사용자 대화형 모드로 실행되고 있지 않습니다.Process is not running in User Interactive mode.
하나 이상의 매개 변수가 MsgBoxResult
또는 MsgBoxStyle
열거형의 멤버가 아닙니다.One or more parameters not a member of MsgBoxResult
or MsgBoxStyle
enumeration.
예제
이 예에서는 함수를 사용 하 여 MsgBox
대화 상자에 예 및 아니요 단추가 있는 중요 오류 메시지를 표시 합니다.This example uses the MsgBox
function to display a critical-error message in a dialog box with Yes and No buttons. 아니요 단추가 기본 응답으로 지정 됩니다.The No button is specified as the default response. MsgBox
상수 값을 하나의 숫자 식으로 결합 하 여이 작업을 수행 합니다.This is done by combining the MsgBox
constant values into one numeric expression. 이 경우 4 (예/아니요 단추 조합)와 16 ( 중요 한 메시지 창) 및 256 (두 번째 단추를 기본 단추로)을 추가 하면 총 276이 제공 됩니다.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. 함수에서 반환 되는 값은 MsgBox
사용자가 선택한 단추에 따라 달라 집니다. 예를 들어 값이 6 인 경우 아니요는 7 값을 반환 합니다.The value returned by the MsgBox
function depends on the button chosen by the user: Yes returns a value of 6; No returns a value of 7.
' The following example requires that Option Infer be set to On.
' Define the message you want to see inside the message box.
Dim msg = "Do you want to continue?"
' Display a simple message box.
MsgBox(msg)
' Define a title for the message box.
Dim title = "MsgBox Demonstration"
' Add the title to the display.
MsgBox(msg, , title)
' Now define a style for the message box. In this example, the
' message box will have Yes and No buttons, the default will be
' the No button, and a Critical Message icon will be present.
Dim style = MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton2 Or
MsgBoxStyle.Critical
' Display the message box and save the response, Yes or No.
Dim response = MsgBox(msg, style, title)
' Take some action based on the response.
If response = MsgBoxResult.Yes Then
MsgBox("YES, continue!!", , title)
Else
MsgBox("NO, stop!!", , title)
End If
설명
위치 인수를 생략 하는 경우 해당 하는 쉼표 구분 기호를 유지 해야 합니다.If you omit any positional arguments, you must retain the corresponding comma delimiter.
대화 상자에 취소 단추가 표시 되는 경우 ESC 키를 누르면 취소 를 클릭 하는 것과 동일한 효과가 있습니다.If the dialog box displays a Cancel button, pressing the ESC key has the same effect as clicking Cancel
대화 상자에 도움말 단추가 포함 되 면 대화 상자에 대 한 상황에 맞는 도움말이 제공 됩니다.If the dialog box contains a Help button, context-sensitive Help is provided for the dialog box. 그러나 다른 단추 중 하나를 선택할 때까지 값이 반환 되지 않습니다.However, no value is returned until one of the other buttons is chosen. Windows Form 애플리케이션에서 선택 합니다 도움말 실행 단추를 HelpRequested 폼에 대 한 이벤트.In Windows Form applications, choosing the Help button executes the HelpRequested event for the form.
참고
MsgBox
함수는 UIPermission
SafeTopLevelWindows 부분 신뢰 상황에서 실행에 영향을 줄 수 있는 수준에 필요 합니다.The MsgBox
function requires UIPermission
at the SafeTopLevelWindows level, which may affect its execution in partial-trust situations. 자세한 내용은 UIPermission를 참조하세요.For more information, see UIPermission.
MsgBoxStyle
열거형 값은 다음 표에 나와 있습니다.The MsgBoxStyle
enumeration values are listed in the following table.
멤버Member | 값Value | 설명Description |
---|---|---|
멤버Member | 값Value | 설명Description |
OKOnly |
00 | 확인 단추만 표시 합니다.Displays OK button only. |
OKCancel |
11 | 확인 및 취소 단추를 표시 합니다.Displays OK and Cancel buttons. |
AbortRetryIgnore |
22 | 중단, 다시 시도 및 무시 단추를 표시 합니다.Displays Abort, Retry, and Ignore buttons. |
YesNoCancel |
33 | 예, 아니요 및 취소 단추를 표시 합니다.Displays Yes, No, and Cancel buttons. |
YesNo |
44 | 예 및 아니요 단추를 표시 합니다.Displays Yes and No buttons. |
RetryCancel |
55 | 다시 시도 및 취소 단추를 표시 합니다.Displays Retry and Cancel buttons. |
Critical |
1616 | 중요 한 메시지 아이콘을 표시 합니다.Displays Critical Message icon. |
Question |
3232 | 경고 쿼리 아이콘을 표시 합니다.Displays Warning Query icon. |
Exclamation |
4848 | 경고 메시지 아이콘을 표시 합니다.Displays Warning Message icon. |
Information |
6464 | 정보 메시지 아이콘을 표시 합니다.Displays Information Message icon. |
DefaultButton1 |
00 | 첫 번째 단추가 기본 단추입니다.First button is default. |
DefaultButton2 |
256256 | 두 번째 단추가 기본 단추입니다.Second button is default. |
DefaultButton3 |
512512 | 세 번째 단추가 기본 단추입니다.Third button is default. |
ApplicationModal |
00 | 애플리케이션 모달입니다.Application is modal. 사용자는 현재 애플리케이션에서 작업을 계속 하기 전에 messagebox에 응답 해야 합니다.The user must respond to the message box before continuing work in the current application. |
SystemModal |
40964096 | 시스템이 모달입니다.System is modal. 모든 애플리케이션에는 사용자가 messagebox에 응답할 때까지 일시 중단 됩니다.All applications are suspended until the user responds to the message box. |
MsgBoxSetForeground |
6553665536 | 메시지 상자 창을 전경 창으로 지정 합니다.Specifies the message box window as the foreground window. |
MsgBoxRight |
524288524288 | 텍스트를 오른쪽에 맞춥니다.Text is right-aligned. |
MsgBoxRtlReading |
10485761048576 | 히브리어 및 아랍어 시스템에서 텍스트를 오른쪽에서 왼쪽으로 읽도록 지정 합니다.Specifies text should appear as right-to-left reading on Hebrew and Arabic systems. |
첫 번째 값 그룹 (0-5)은 대화 상자에 표시 되는 단추의 수와 유형을 설명 합니다.The first group of values (0-5) describes the number and type of buttons displayed in the dialog box. 두 번째 그룹 (16, 32, 48, 64)은 아이콘 스타일을 설명 합니다.The second group (16, 32, 48, 64) describes the icon style. 세 번째 그룹 (0, 256, 512)에 따라 기본값 단추가 결정 됩니다.The third group (0, 256, 512) determines which button is the default. 네 번째 그룹 (0, 4096)은 메시지 상자의 모달을 결정 하 고 다섯 번째 그룹은 메시지 상자 창이 전경 창 인지 여부와 텍스트의 맞춤 및 방향을 지정 합니다.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. 숫자를 추가 하 여 인수의 최종 값을 만들 때는 Buttons
각 그룹의 숫자를 하나만 사용 합니다.When adding numbers to create a final value for the Buttons
argument, use only one number from each group.