MessageBox クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


MessageBox クラスの新しいインスタンスは作成できません。メッセージ ボックスを表示するには、static メソッドの MessageBox.Show を呼び出します。メッセージ ボックスに表示されるタイトル、メッセージ、ボタン、およびアイコンは、このメソッドに渡すパラメータによって決定されます。

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.Windows.Forms.MessageBox


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MessageBox メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | Show | オーバーロードされます。 メッセージ ボックスを表示します。 |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

MessageBox メンバ
メッセージ ボックスを表示します。メッセージ ボックスには、テキスト、ボタン、およびユーザーに情報や指示を伝えるための記号を格納できます。
MessageBox データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | Show | オーバーロードされます。 メッセージ ボックスを表示します。 |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

MESSAGE BOX
出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2021/04/11 14:35 UTC 版)
「CD&DLでーた」の記事における「MESSAGE BOX」の解説
※この「MESSAGE BOX」の解説は、「CD&DLでーた」の解説の一部です。
「MESSAGE BOX」を含む「CD&DLでーた」の記事については、「CD&DLでーた」の概要を参照ください。
- message boxのページへのリンク