MessageBox 클래스

정의

사용자에게 메시지를 보여 주는 메시지 창을 표시합니다. 이 창을 대화 상자라고도 합니다. 이 창은 사용자가 닫을 때까지 애플리케이션의 다른 동작을 차단하는 모달 창입니다. MessageBox에는 사용자에게 필요한 정보와 명령을 제공하는 텍스트, 단추 및 기호가 포함될 수 있습니다.

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

예제

다음 코드 예제를 사용 하는 방법을 보여 줍니다는 MessageBox 에서 누락 된 항목의 사용자에 게는 TextBox합니다. 이 예제에서는 메서드를 사용 하 여 기존 폼에서 호출 되는 한 TextBox 라는 ServerName 에 합니다.

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 클래스입니다. 메시지 상자를 표시 하려면 호출을 static 메서드 MessageBox.Show합니다. 제목, 메시지, 단추 및 메시지 상자에 표시 되는 아이콘은이 메서드에 전달 하는 매개 변수에 의해 결정 됩니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

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

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

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

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

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

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

(다음에서 상속됨 Object)
Show(IWin32Window, String)

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

Show(IWin32Window, String, String)

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

Show(IWin32Window, String, String, MessageBoxButtons)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Show(String)

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

Show(String, String)

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

Show(String, String, MessageBoxButtons)

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

Show(String, String, MessageBoxButtons, MessageBoxIcon)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ToString()

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

(다음에서 상속됨 Object)

적용 대상

추가 정보