MessageBox 클래스

정의

사용자에게 메시지를 표시하는 대화 상자라고도 하는 메시지 창을 표시합니다. 사용자가 닫을 때까지 애플리케이션의 다른 작업을 차단하는 모달 창입니다. A MessageBox 는 사용자에게 알리고 지시하는 텍스트, 단추 및 기호를 포함할 수 있습니다.

public ref class MessageBox
public class MessageBox
type MessageBox = class
Public Class MessageBox
상속
MessageBox

예제

다음 코드 예제에서는 a를 사용하여 MessageBox 사용자에게 누락된 항목을 TextBox알리는 방법을 보여줍니다. 이 예제에서는 명명된 ServerName이 있는 기존 양식에서 메서드를 TextBox 호출해야 합니다.

private:
   void validateUserEntry()
   {
      // Checks the value of the text.
      if ( serverName->Text->Length == 0 )
      {
         // Initializes the variables to pass to the MessageBox::Show method.
         String^ message = "You did not enter a server name. Cancel this operation?";
         String^ caption = "No Server Name Specified";
         MessageBoxButtons buttons = MessageBoxButtons::YesNo;
         System::Windows::Forms::DialogResult result;

         // Displays the MessageBox.
         result = MessageBox::Show( this, message, caption, buttons );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }
private void validateUserEntry()
{
    // Checks the value of the text.
    if(serverName.Text.Length == 0)
    {
        // Initializes the variables to pass to the MessageBox.Show method.
        string message = "You did not enter a server name. Cancel this operation?";
     string caption = "Error Detected in Input";
        MessageBoxButtons buttons = MessageBoxButtons.YesNo;
        DialogResult result;

        // Displays the MessageBox.
        result = MessageBox.Show(message, caption, buttons);
        if (result == System.Windows.Forms.DialogResult.Yes)
        {
            // Closes the parent form.
            this.Close();
        }
    }
}
Private Sub ValidateUserEntry()
    ' Checks the value of the text.
    If ServerName.Text.Length = 0 Then

        ' Initializes variables to pass to the MessageBox.Show method.
        Dim Message As String = "You did not enter a server name. Cancel this operation?"
        Dim Caption As String = "Error Detected in Input"
        Dim Buttons As MessageBoxButtons = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays the MessageBox
        Result = MessageBox.Show(Message, Caption, Buttons)

        ' Gets the result of the MessageBox display.
        If Result = System.Windows.Forms.DialogResult.Yes Then
            ' Closes the parent form.
            Me.Close()
        End If
    End If
End Sub

다음 코드 예제에서는 사용자에게 예 또는 아니요 질문을 하고 응답에 따라 결정을 내리는 방법을 보여 드립니다.

private:
   void Form1_FormClosing(Object^ sender, FormClosingEventArgs^ e)
   {
      // If the no button was pressed ...
      if ((MessageBox::Show(
         "Are you sure that you would like to close the form?", 
         "Form Closing", MessageBoxButtons::YesNo, 
         MessageBoxIcon::Question) == DialogResult::No))
      {
         // cancel the closure of the form.
         e->Cancel = true;
      }
   }
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    const string message =
        "Are you sure that you would like to close the form?";
    const string caption = "Form Closing";
    var result = MessageBox.Show(message, caption,
                                 MessageBoxButtons.YesNo,
                                 MessageBoxIcon.Question);

    // If the no button was pressed ...
    if (result == DialogResult.No)
    {
        // cancel the closure of the form.
        e.Cancel = true;
    }
}
Private Sub Form1_FormClosing( _
    ByVal sender As System.Object, _
    ByVal e As System.Windows.Forms.FormClosingEventArgs) _
    Handles MyBase.FormClosing

    Dim message As String = _
            "Are you sure that you would like to close the form?"
    Dim caption As String = "Form Closing"
    Dim result = MessageBox.Show(message, caption, _
                                 MessageBoxButtons.YesNo, _
                                 MessageBoxIcon.Question)

    ' If the no button was pressed ...
    If (result = DialogResult.No) Then
        ' cancel the closure of the form.
        e.Cancel = True
    End If
End Sub

설명

클래스의 MessageBox 새 인스턴스를 만들 수 없습니다. 메시지 상자를 표시하려면 메서드MessageBox.Show를 호출합니다static. 메시지 상자에 표시되는 제목, 메시지, 단추 및 아이콘은 이 메서드에 전달하는 매개 변수에 따라 결정됩니다.

메서드

Name Description
Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object)

지정된 도움말 파일 HelpNavigator및 도움말 항목을 사용하여 지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추, 옵션 및 도움말 단추가 있는 메시지 상자를 표시합니다.

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator)

지정된 도움말 파일을 사용하여 지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추, 옵션 및 도움말 단추가 있는 메시지 상자를 표시합니다 HelpNavigator.

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String)

지정된 도움말 파일 및 도움말 키워드를 사용하여 지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추, 옵션 및 도움말 단추가 있는 메시지 상자를 표시합니다.

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String)

지정된 도움말 파일을 사용하여 지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추, 옵션 및 도움말 단추가 있는 메시지 상자를 표시합니다.

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions)

지정된 개체 앞에 지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추 및 옵션이 있는 메시지 상자를 표시합니다.

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)

지정된 개체 앞에 지정된 텍스트, 캡션, 단추, 아이콘 및 기본 단추가 있는 메시지 상자를 표시합니다.

Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon)

지정된 개체 앞에 지정된 텍스트, 캡션, 단추 및 아이콘이 있는 메시지 상자를 표시합니다.

Show(IWin32Window, String, String, MessageBoxButtons)

지정된 개체 앞에 지정된 텍스트, 캡션 및 단추가 있는 메시지 상자를 표시합니다.

Show(IWin32Window, String, String)

지정된 개체 앞에 지정된 텍스트와 캡션이 있는 메시지 상자를 표시합니다.

Show(IWin32Window, String)

지정된 개체 앞에 지정된 텍스트가 있는 메시지 상자를 표시합니다.

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, Boolean)

지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추, 옵션 및 도움말 단추가 있는 메시지 상자를 표시합니다.

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object)

지정된 도움말 파일 HelpNavigator및 도움말 항목을 사용하여 지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추, 옵션 및 도움말 단추가 있는 메시지 상자를 표시합니다.

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator)

지정된 도움말 파일을 사용하여 지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추, 옵션 및 도움말 단추가 있는 메시지 상자를 표시합니다 HelpNavigator.

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String)

지정된 도움말 파일 및 도움말 키워드를 사용하여 지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추, 옵션 및 도움말 단추가 있는 메시지 상자를 표시합니다.

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String)

지정된 도움말 파일을 사용하여 지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추, 옵션 및 도움말 단추가 있는 메시지 상자를 표시합니다.

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions)

지정된 텍스트, 캡션, 단추, 아이콘, 기본 단추 및 옵션이 있는 메시지 상자를 표시합니다.

Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)

지정된 텍스트, 캡션, 단추, 아이콘 및 기본 단추가 있는 메시지 상자를 표시합니다.

Show(String, String, MessageBoxButtons, MessageBoxIcon)

지정된 텍스트, 캡션, 단추 및 아이콘이 있는 메시지 상자를 표시합니다.

Show(String, String, MessageBoxButtons)

지정된 텍스트, 캡션 및 단추가 있는 메시지 상자를 표시합니다.

Show(String, String)

지정된 텍스트와 캡션이 있는 메시지 상자를 표시합니다.

Show(String)

지정된 텍스트가 있는 메시지 상자를 표시합니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보