MessageBox クラスとは? わかりやすく解説

MessageBox クラス

メッセージ ボックス表示しますメッセージ ボックスには、テキストボタン、およびユーザー情報指示伝えるための記号格納できます

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

解説解説
使用例使用例

MessageBox使用してTextBoxデータ入力されていないことをユーザー通知する方法次のコード例示します。この例では、このメソッドButton および TextBox配置され既存フォームから呼び出す必要があります

Private Sub button1_Click(sender As
 Object, e As System.EventArgs)
    If textBox1.Text = "" Then
        MessageBox.Show("You must enter a name.",
 "Name Entry Error", _
           MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
    Else
        ' Code to act on the data entered would go here.
    End If
End Sub
private void button1_Click(object sender, System.EventArgs
 e) {
   if(textBox1.Text == "") {
      MessageBox.Show("You must enter a name.", "Name Entry Error"
,
         MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
   }
   else {
      // Code to act on the data entered would go here.
   }
}
private:
   void button1_Click( Object^ sender, System::EventArgs^ e )
   {
      if ( textBox1->Text->Equals( "" ) )
      {
         MessageBox::Show( "You must enter a name.", "Name Entry Error"
,
            MessageBoxButtons::OK, MessageBoxIcon::Exclamation );
      }
      else
      {
         // Code to act on the data entered would go here.
      }
   }
protected void button1_Click(Object sender,
 System.EventArgs e)
{
    if (textBox1.get_Text().Equals("")) {
        MessageBox.Show("You must enter a name.", "Name Entry Error"
,
            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    else {
        // Code to act on the data entered would go here.
    } 
} //button1_Click

はい、またはいいえで答え質問ユーザー提示し、その回答基づいて決定を行う方法次のコード例示します

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 = DialogResult.Yes Then

            ' Closes the parent form.

            Me.Close()

        End If

    End If

End Sub
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 == 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 = "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.get_Text().get_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;
        DialogResult result;

        // Displays the MessageBox.
        result = MessageBox.Show(this, message, caption, buttons);

        if (result.Equals(DialogResult.Yes)) {
            // Closes the parent form.
            this.Close();
        }
    }
} //ValidateUserEntry
継承階層継承階層
System.Object
  System.Windows.Forms.MessageBox
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「MessageBox クラス」の関連用語

MessageBox クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



MessageBox クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS