MessageBox.Show メソッド

定義

メッセージ ボックスを表示します。

オーバーロード

Show(String)

指定したテキストを表示するメッセージ ボックスを表示します。

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイルとヘルプ キーワードを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイル、HelpNavigator、およびヘルプ トピックを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

Show(IWin32Window, 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, String)

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイルとヘルプ キーワードを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

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

指定したオブジェクトの前に、指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、およびオプションを表示するメッセージ ボックスを表示します。

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイルを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイルと HelpNavigator を使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

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

指定したオブジェクトの前に、指定したテキスト、キャプション、ボタン、アイコン、および既定のボタンを表示するメッセージ ボックスを表示します。

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

指定したオブジェクトの前に、指定したテキスト、キャプション、ボタン、およびアイコンを表示するメッセージ ボックスを表示します。

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

指定したテキスト、キャプション、ボタン、アイコン、および既定のボタンを表示するメッセージ ボックスを表示します。

Show(IWin32Window, String, String, MessageBoxButtons)

指定したオブジェクトの前に、指定したテキスト、キャプション、およびボタンを表示するメッセージ ボックスを表示します。

Show(String, String, MessageBoxButtons, MessageBoxIcon)

指定したテキスト、キャプション、ボタン、およびアイコンを表示するメッセージ ボックスを表示します。

Show(IWin32Window, String, String)

指定したオブジェクトの前に、指定したテキストとキャプションを表示するメッセージ ボックスを表示します。

Show(String, String, MessageBoxButtons)

指定したテキスト、キャプション、およびボタンを表示するメッセージ ボックスを表示します。

Show(IWin32Window, String)

指定したオブジェクトの前に、指定したテキストを表示するメッセージ ボックスを表示します。

Show(String, String)

指定したテキストとキャプションを表示するメッセージ ボックスを表示します。

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、およびオプションを表示するメッセージ ボックスを表示します。

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイル、HelpNavigator、およびヘルプ トピックを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

Show(String)

指定したテキストを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text);
public static System.Windows.Forms.DialogResult Show (string text);
public static System.Windows.Forms.DialogResult Show (string? text);
static member Show : string -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

戻り値

DialogResult 値のいずれか 1 つ。

次のコード例では、単純なメッセージ ボックスを表示します。

private void DisplayMessageBoxText()
{
         MessageBox.Show("Hello, world.");
}
Private Sub DisplayMessageBoxText()

    MessageBox.Show("Hello, world.")
End Sub

注釈

既定では、メッセージ ボックスに [OK] ボタンが表示されます。 メッセージ ボックスには、タイトルにキャプションが含まれていません。

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイルとヘルプ キーワードを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::String ^ keyword);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, string keyword);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, string keyword);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, keyword As String) As DialogResult

パラメーター

owner
IWin32Window

モーダル ダイアログ ボックスを所有する IWin32Window の実装。

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

helpFilePath
String

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ ファイルのパスと名前。

keyword
String

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ キーワード。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

- または -

指定した defaultButton が、MessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例では、メイン ウィンドウの親となるメッセージ ボックスを表示する方法を示します。 メッセージ ボックスに [ヘルプ] ボタンが表示されます。 ユーザーが [ヘルプ] ボタンをクリックすると、Mspaint.chmヘルプ ファイルが開き、キーワード (keyword)によってmspaint.chm::/paint_brush.htm識別されたトピックが表示されます。 この例では、ヘルプ ファイルが Mspaint.chm インストールされている必要があります。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file, 
// and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
// associated topic.
System::Windows::Forms::DialogResult r8 = MessageBox::Show( this, "Message with Help file and keyword.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", "mspaint.chm::/paint_brush.htm" );
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file, 
// and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
// associated topic.
DialogResult r8 = MessageBox.Show (this, "Message with Help file and keyword.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 0, 
                                   "mspaint.chm", 
                                   "mspaint.chm::/paint_brush.htm");
' Display message box parented to the main form. 
' The Help button opens the Mspaint.chm Help file, 
' and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
' associated topic.
Dim r8 As DialogResult = MessageBox.Show(Me, "Message with Help file and keyword.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, 0, _
                                   "mspaint.chm", _
                                   "mspaint.chm::/paint_brush.htm")

注釈

メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォーム (通常はユーザーの操作に応じて) を非表示または閉じる必要があります。 パラメーターを owner 使用して、ダイアログ ボックスの最上位の所有者として機能するインターフェイスを IWin32Window 実装する特定のオブジェクトを指定できます。

ユーザーが [ヘルプ] ボタンをクリックすると、 パラメーターでhelpFilePath指定されたヘルプ ファイルが開き、 パラメーターでkeyword識別されるヘルプ キーワード (keyword) トピックが表示されます。 メッセージ ボックス (またはアクティブフォーム) を所有するフォームもイベントを HelpRequested 受け取ります。

こちらもご覧ください

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイル、HelpNavigator、およびヘルプ トピックを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::Windows::Forms::HelpNavigator navigator, System::Object ^ param);
public static System.Windows.Forms.DialogResult Show (string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator, object param);
public static System.Windows.Forms.DialogResult Show (string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator, object? param);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * System.Windows.Forms.HelpNavigator * obj -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, navigator As HelpNavigator, param As Object) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

helpFilePath
String

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ ファイルのパスと名前。

navigator
HelpNavigator

HelpNavigator 値のいずれか 1 つ。

param
Object

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ トピックの数値 ID。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

- または -

指定した defaultButton が、MessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例では、[ヘルプ] ボタンを使用してメッセージ ボックスを表示する方法を示します。 ユーザーが [ヘルプ] ボタンをクリックすると、Mspaint.chmヘルプ ファイルが開き、[ヘルプ インデックス] タブと、キーワード (keyword)でovals識別されたトピックが表示されます。 この例では、ヘルプ ファイルが Mspaint.chm インストールされている必要があります。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box. The Help button opens the Mspaint.chm Help file, 
// shows index with the "ovals" keyword selected, and displays the
// associated topic.
System::Windows::Forms::DialogResult r5 = MessageBox::Show( "Message with Help file and Help navigator with additional parameter.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", HelpNavigator::KeywordIndex, "ovals" );
// Display a message box. The Help button opens the Mspaint.chm Help file, 
// shows index with the "ovals" keyword selected, and displays the
// associated topic.
DialogResult r5 = MessageBox.Show ("Message with Help file and Help navigator with additional parameter.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, "mspaint.chm", 
                                   HelpNavigator.KeywordIndex, "ovals");
' Display a message box. The Help button opens the Mspaint.chm Help file, 
' shows index with the "ovals" keyword selected, and displays the
' associated topic.
Dim r5 As DialogResult = MessageBox.Show("Message with Help file and Help navigator with additional parameter.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, "mspaint.chm", _
                                   HelpNavigator.KeywordIndex, "ovals")

注釈

メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォーム (通常はユーザーの操作に応じて) を非表示または閉じる必要があります。

ユーザーが [ヘルプ] ボタンをクリックすると、 パラメーターで helpFilePath 指定されたヘルプ ファイルが開き、 パラメーターで navigator 識別されるヘルプ コンテンツが表示されます。 メッセージ ボックス (またはアクティブフォーム) を所有するフォームもイベントを HelpRequested 受け取ります。

コンパイルされたヘルプ ファイルは、目次、インデックス、検索、ページ内のキーワード (keyword)リンクを提供します。 、または には、次の値をnavigatorIndexTableOfContentsFind使用できます。Topic

を使用 param して、コマンドをさらに絞り込 Topic むことができます。 パラメーターで navigator 指定された値が TableOfContents、、 Indexまたは Findの場合、この値は である null必要があります。 パラメーターが を参照Topicしているnavigator場合、この値は、表示するトピックの数値を含むオブジェクトを参照する必要があります。

パラメーターの形式は helpFilePath C:\path\sample.chm または /folder/file.htm です。

こちらもご覧ください

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイルを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String) As DialogResult

パラメーター

owner
IWin32Window

モーダル ダイアログ ボックスを所有する IWin32Window の実装。

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

helpFilePath
String

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ ファイルのパスと名前。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

- または -

指定した defaultButton が、MessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例では、メイン フォームを親とするメッセージ ボックスを表示する方法を示します。 メッセージ ボックスに [ヘルプ] ボタンが表示されます。 ユーザーが [ヘルプ] ボタンをクリックすると、 Mspaint.chm ヘルプ ファイルが開きます。 この例では、ヘルプ ファイルが Mspaint.chm インストールされている必要があります。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file.
System::Windows::Forms::DialogResult r2 = MessageBox::Show( this, "Message with Help file.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm" );
// Display a message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file.
DialogResult r2 = MessageBox.Show (this, "Message with Help file.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, 
                                   "mspaint.chm");
' Display a message box parented to the main form. 
' The Help button opens the Mspaint.chm Help file.
Dim r2 As DialogResult = MessageBox.Show(Me, "Message with Help file.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, _
                                   "mspaint.chm")

注釈

メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォーム (通常はユーザーの操作に応じて) を非表示または閉じる必要があります。 パラメーターを owner 使用して、ダイアログ ボックスの最上位ウィンドウおよび所有者として機能するインターフェイスを IWin32Window 実装する特定のオブジェクトを指定できます。

ユーザーが [ヘルプ] ボタンをクリックすると、 パラメーターで helpFilePath 指定されたヘルプ ファイルが開きます。 メッセージ ボックス (またはアクティブフォーム) を所有するフォームもイベントを HelpRequested 受け取ります。

パラメーターの形式は helpFilePath C:\path\sample.chm または /folder/file.htm です。

こちらもご覧ください

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイルと HelpNavigator を使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::Windows::Forms::HelpNavigator navigator);
public static System.Windows.Forms.DialogResult Show (string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator);
public static System.Windows.Forms.DialogResult Show (string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * System.Windows.Forms.HelpNavigator -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, navigator As HelpNavigator) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

helpFilePath
String

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ ファイルのパスと名前。

navigator
HelpNavigator

HelpNavigator 値のいずれか 1 つ。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

- または -

指定した defaultButton が、MessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例では、[ヘルプ] ボタンを使用してメッセージ ボックスを表示する方法を示します。 ユーザーが [ヘルプ] ボタンをクリックすると、 Mspaint.chm ヘルプ ファイルが開き、[ヘルプ インデックス] タブが表示されます。 この例では、ヘルプ ファイルが Mspaint.chm インストールされている必要があります。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box. The Help button opens 
// the Mspaint.chm Help file and shows the Help contents 
// on the Index tab.
System::Windows::Forms::DialogResult r3 = MessageBox::Show( "Message with Help file and Help navigator.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", HelpNavigator::Index );
// Display a message box. The Help button opens 
// the Mspaint.chm Help file and shows the Help contents 
// on the Index tab.
DialogResult r3 = MessageBox.Show ("Message with Help file and Help navigator.", 
                                   "Help Caption", MessageBoxButtons.OK,
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, "mspaint.chm", 
                                   HelpNavigator.Index);
' Display a message box. The Help button opens 
' the Mspaint.chm Help file and shows the Help contents 
' on the Index tab.
Dim r3 As DialogResult = MessageBox.Show("Message with Help file and Help navigator.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, "mspaint.chm", _
                                   HelpNavigator.Index)

注釈

メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォーム (通常はユーザーの操作に応じて) を非表示または閉じる必要があります。

ユーザーが [ヘルプ] ボタンをクリックすると、 パラメーターで helpFilePath 指定されたヘルプ ファイルが開き、 パラメーターによって navigator 識別されるヘルプ コンテンツが表示されます。 メッセージ ボックス (またはアクティブフォーム) を所有するフォームもイベントを HelpRequested 受け取ります。

コンパイル済みヘルプ ファイルは、目次、インデックス、検索、ページ内のキーワード (keyword)リンクを提供します。 、または には、次の値をnavigatorIndexTableOfContentsFind使用できます。Topic

パラメーターの形式は helpFilePath C:\path\sample.chm または /folder/file.htm です。

こちらもご覧ください

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイルとヘルプ キーワードを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::String ^ keyword);
public static System.Windows.Forms.DialogResult Show (string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, string keyword);
public static System.Windows.Forms.DialogResult Show (string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, string keyword);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, keyword As String) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

helpFilePath
String

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ ファイルのパスと名前。

keyword
String

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ キーワード。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

- または -

指定した defaultButton が、MessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例では、[ヘルプ] ボタンを使用してメッセージ ボックスを表示する方法を示します。 ユーザーが [ヘルプ] ボタンをクリックすると、Mspaint.chmヘルプ ファイルが開き、キーワード (keyword)によってmspaint.chm::/paint_brush.htm識別されたトピックが表示されます。 この例では、ヘルプ ファイルが Mspaint.chm インストールされている必要があります。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box. The Help button opens the Mspaint.chm Help file, 
// and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
// associated topic.
System::Windows::Forms::DialogResult r7 = MessageBox::Show( "Message with Help file and keyword.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", "mspaint.chm::/paint_brush.htm" );
// Display a message box. The Help button opens the Mspaint.chm Help file, 
// and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
// associated topic.
DialogResult r7 = MessageBox.Show ("Message with Help file and keyword.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 0, 
                                   "mspaint.chm", 
                                   "mspaint.chm::/paint_brush.htm");
' Display a message box. The Help button opens the Mspaint.chm Help file, 
' and the "mspaint.chm::/paint_brush.htm" Help keyword shows the 
' associated topic.
Dim r7 As DialogResult = MessageBox.Show("Message with Help file and keyword.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, 0, _
                                   "mspaint.chm", _
                                   "mspaint.chm::/paint_brush.htm")

注釈

メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。

ユーザーが [ヘルプ] ボタンをクリックすると、 パラメーターでhelpFilePath指定されたヘルプ ファイルが開き、 パラメーターでkeyword識別されるヘルプ キーワード (keyword) トピックが表示されます。 メッセージ ボックス (またはアクティブフォーム) を所有するフォームもイベントを HelpRequested 受け取ります。

こちらもご覧ください

適用対象

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

指定したオブジェクトの前に、指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、およびオプションを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions) As DialogResult

パラメーター

owner
IWin32Window

モーダル ダイアログ ボックスを所有する IWin32Window の実装。

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

または

defaultButtonMessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

options に、DefaultDesktopOnly または ServiceNotification、および owner パラメーターの値が指定されています。 これら 2 つのオプションは、このメソッドの owner パラメーターをとらないバージョンを起動する場合にだけ使用するようにしてください。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例では、 のこのオーバーロードShowでサポートされているオプションを使用して をMessageBox表示する方法を示します。 文字列変数 ServerNameが空であることを確認した後、この例では を表示 MessageBoxし、操作を取り消すオプションをユーザーに提供します。 メソッドの Show 戻り値が に Yes評価された場合、 を表示した MessageBox フォームは閉じられます。

private:
   void validateUserEntry2()
   {
      // 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, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, MessageBoxOptions::RightAlign );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }

private void validateUserEntry2()
{

    // 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;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 
            MessageBoxOptions.RightAlign);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry2()


    ' 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 = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)


        ' 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

注釈

パラメーターを owner 使用すると、ダイアログ ボックスの最上位ウィンドウと所有者として機能するインターフェイスを IWin32Window 実装する特定のオブジェクトを指定できます。 メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。

メッセージ ボックスには、最大 3 つのボタンを含めることができます。

こちらもご覧ください

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイルを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath);
public static System.Windows.Forms.DialogResult Show (string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath);
public static System.Windows.Forms.DialogResult Show (string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

helpFilePath
String

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ ファイルのパスと名前。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

- または -

指定した defaultButton が、MessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例は、[ヘルプ] ボタンを含むメッセージ ボックスを表示する方法を示しています。 ユーザーが [ヘルプ] ボタンをクリックすると、 Mspaint.chm ヘルプ ファイルが開きます。 この例では、ヘルプ ファイルが Mspaint.chm インストールされている必要があります。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box with a help button. 
// The Help button opens the Mspaint.chm Help file.
System::Windows::Forms::DialogResult r1 = MessageBox::Show( "Message with Help file.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm" );
// Display a message box with a help button. 
// The Help button opens the Mspaint.chm Help file.
DialogResult r1 = MessageBox.Show ("Message with Help file.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, 
                                   "mspaint.chm");
' Display a message box with a help button. 
' The Help button opens the Mspaint.chm Help file.
Dim r1 As DialogResult = MessageBox.Show("Message with Help file.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, _
                                   "mspaint.chm")

注釈

メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。

ユーザーが [ヘルプ] ボタンをクリックすると、 パラメーターで helpFilePath 指定されたヘルプ ファイルが開きます。 メッセージ ボックス (またはアクティブフォーム) を所有するフォームもイベントを HelpRequested 受け取ります。

パラメーターの形式は helpFilePath C:\path\sample.chm または /folder/file.htm です。

こちらもご覧ください

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, bool displayHelpButton);
public static System.Windows.Forms.DialogResult Show (string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, bool displayHelpButton);
public static System.Windows.Forms.DialogResult Show (string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, bool displayHelpButton);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * bool -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, displayHelpButton As Boolean) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

displayHelpButton
Boolean

[ヘルプ] ボタンを表示する場合は true。それ以外の場合は false。 既定値は、false です。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

- または -

指定した defaultButton が、MessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例では、メッセージ ボックスに [ヘルプ] ボタンを表示し、イベントを Control.HelpRequested 処理し、イベントに応答してカスタム ヘルプ ウィンドウを表示する方法を示します。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display a message box with a Help button. Show a custom Help window
// by handling the HelpRequested event.
System::Windows::Forms::DialogResult AlertMessageWithCustomHelpWindow()
{
   
   // Handle the HelpRequested event for the following message.
   this->HelpRequested += gcnew System::Windows::Forms::HelpEventHandler( this, &Form1::Form1_HelpRequested );
   this->Tag = "Message with Help button.";
   
   // Show a message box with OK and Help buttons.
   System::Windows::Forms::DialogResult r = MessageBox::Show( "Message with Help button.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, true );
   
   // Remove the HelpRequested event handler to keep the event
   // from being handled for other message boxes.
   this->HelpRequested -= gcnew System::Windows::Forms::HelpEventHandler( this, &Form1::Form1_HelpRequested );
   
   // Return the dialog box result.
   return r;
}

void Form1_HelpRequested( System::Object^ sender, System::Windows::Forms::HelpEventArgs^ hlpevent )
{
   
   // Create a custom Help window in response to the HelpRequested event.
   Form^ helpForm = gcnew Form;
   
   // Set up the form position, size, and title caption.
   helpForm->StartPosition = FormStartPosition::Manual;
   helpForm->Size = System::Drawing::Size( 200, 400 );
   helpForm->DesktopLocation = Point(this->DesktopBounds.X + this->Size.Width,this->DesktopBounds.Top);
   helpForm->Text = "Help Form";
   
   // Create a label to contain the Help text.
   Label^ helpLabel = gcnew Label;
   
   // Add the label to the form and set its text.
   helpForm->Controls->Add( helpLabel );
   helpLabel->Dock = DockStyle::Fill;
   
   // Use the sender parameter to identify the context of the Help request.
   // The parameter must be cast to the Control type to get the Tag property.
   Control^ senderControl = dynamic_cast<Control^>(sender);
   helpLabel->Text = String::Format( "Help information shown in response to user action on the '{0}' message.", dynamic_cast<String^>(senderControl->Tag) );
   
   // Set the Help form to be owned by the main form. This helps
   // to ensure that the Help form is disposed of.
   this->AddOwnedForm( helpForm );
   
   // Show the custom Help window.
   helpForm->Show();
   
   // Indicate that the HelpRequested event is handled.
   hlpevent->Handled = true;
}
// Display a message box with a Help button. Show a custom Help window
// by handling the HelpRequested event.
private DialogResult AlertMessageWithCustomHelpWindow ()
{
    // Handle the HelpRequested event for the following message.
    this.HelpRequested += new System.Windows.Forms.HelpEventHandler (this.Form1_HelpRequested);

    this.Tag = "Message with Help button.";

    // Show a message box with OK and Help buttons.
    DialogResult r = MessageBox.Show ("Message with Help button.", 
                                      "Help Caption", MessageBoxButtons.OK, 
                                      MessageBoxIcon.Question, 
                                      MessageBoxDefaultButton.Button1, 
                                      0, true);

    // Remove the HelpRequested event handler to keep the event
    // from being handled for other message boxes.
    this.HelpRequested -= new System.Windows.Forms.HelpEventHandler (this.Form1_HelpRequested);

    // Return the dialog box result.
    return r;
}

private void Form1_HelpRequested (System.Object sender, System.Windows.Forms.HelpEventArgs hlpevent)
{
    // Create a custom Help window in response to the HelpRequested event.
    Form helpForm = new Form ();

    // Set up the form position, size, and title caption.
    helpForm.StartPosition = FormStartPosition.Manual;
    helpForm.Size = new Size (200, 400);
    helpForm.DesktopLocation = new Point (this.DesktopBounds.X + 
                                          this.Size.Width, 
                                          this.DesktopBounds.Top);
    helpForm.Text = "Help Form";

    // Create a label to contain the Help text.
    Label helpLabel = new Label ();

    // Add the label to the form and set its text.
    helpForm.Controls.Add (helpLabel);
    helpLabel.Dock = DockStyle.Fill;

    // Use the sender parameter to identify the context of the Help request.
    // The parameter must be cast to the Control type to get the Tag property.
    Control senderControl = sender as Control;

    helpLabel.Text = "Help information shown in response to user action on the '" + 
                      (string)senderControl.Tag + "' message.";

    // Set the Help form to be owned by the main form. This helps
    // to ensure that the Help form is disposed of.
    this.AddOwnedForm (helpForm);

    // Show the custom Help window.
    helpForm.Show ();

    // Indicate that the HelpRequested event is handled.
    hlpevent.Handled = true;
}
' Display a message box with a Help button. Show a custom Help window
' by handling the HelpRequested event.
Private Function AlertMessageWithCustomHelpWindow() As DialogResult

    ' Handle the HelpRequested event for the following message.
    AddHandler Me.HelpRequested, AddressOf Me.Form1_HelpRequested

    Me.Tag = "Message with Help button."

    ' Show a message box with OK and Help buttons.
    Dim r As DialogResult = MessageBox.Show("Message with Help button.", _
                                          "Help Caption", MessageBoxButtons.OK, _
                                          MessageBoxIcon.Question, _
                                          MessageBoxDefaultButton.Button1, _
                                          0, True)

    ' Remove the HelpRequested event handler to keep the event
    ' from being handled for other message boxes.
    RemoveHandler Me.HelpRequested, AddressOf Me.Form1_HelpRequested

    ' Return the dialog box result.
    Return r
End Function

Private Sub Form1_HelpRequested(ByVal sender As System.Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs)

    ' Create a custom Help window in response to the HelpRequested event.
    Dim helpForm As Form = New Form

    ' Set up the form position, size, and title caption.
    With helpForm
        .StartPosition = FormStartPosition.Manual
        .Size = New Size(200, 400)
        .DesktopLocation = New Point(Me.DesktopBounds.X + _
                                     Me.Size.Width, Me.DesktopBounds.Top)
        .Text = "Help Form"
    End With

    ' Create a label to contain the Help text.
    Dim helpLabel As Label = New Label

    ' Add the label to the form and set its text.
    helpForm.Controls.Add(helpLabel)
    helpLabel.Dock = DockStyle.Fill

    ' Use the sender parameter to identify the context of the Help request.
    ' The parameter must be cast to the Control type to get the Tag property.
    Dim senderControl As Control = CType(sender, Control)

    helpLabel.Text = "Help information shown in response to user action on the '" & _
                      CStr(senderControl.Tag) & "' message."

    ' Set the Help form to be owned by the main form. This helps
    ' to ensure that the Help form is disposed of.
    Me.AddOwnedForm(helpForm)

    ' Show the custom Help window.
    helpForm.Show()

    ' Indicate that the HelpRequested event is handled.
    hlpevent.Handled = True
End Sub

注釈

メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。

ユーザーが [ヘルプ] ボタンをクリックすると、メッセージ ボックス (またはアクティブなフォーム) を所有するフォームがイベントを HelpRequested 受け取ります。 イベントを HelpRequested 処理してカスタム ヘルプ アクションを実行します。

こちらもご覧ください

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイルと HelpNavigator を使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::Windows::Forms::HelpNavigator navigator);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * System.Windows.Forms.HelpNavigator -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, navigator As HelpNavigator) As DialogResult

パラメーター

owner
IWin32Window

モーダル ダイアログ ボックスを所有する IWin32Window の実装。

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

helpFilePath
String

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ ファイルのパスと名前。

navigator
HelpNavigator

HelpNavigator 値のいずれか 1 つ。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

- または -

指定した defaultButton が、MessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例は、メイン ウィンドウに親されたメッセージ ボックスを表示する方法を示しています。 メッセージ ボックスに [ヘルプ] ボタンが表示されます。 ユーザーが [ヘルプ] ボタンをクリックすると、 Mspaint.chm ヘルプ ファイルが開き、[ヘルプ インデックス] タブが表示されます。 この例では、ヘルプ ファイルが Mspaint.chm インストールされている必要があります。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file
// and shows the Help contents on the Index tab.
System::Windows::Forms::DialogResult r4 = MessageBox::Show( this, "Message with Help file and Help navigator.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", HelpNavigator::Index );
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file
// and shows the Help contents on the Index tab.
DialogResult r4 = MessageBox.Show (this, 
                                   "Message with Help file and Help navigator.", 
                                   "Help Caption", MessageBoxButtons.OK,
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, "mspaint.chm", 
                                   HelpNavigator.Index);
' Display message box parented to the main form. 
' The Help button opens the Mspaint.chm Help file
' and shows the Help contents on the Index tab.
Dim r4 As DialogResult = MessageBox.Show(Me, _
                                      "Message with Help file and Help navigator.", _
                                      "Help Caption", MessageBoxButtons.OK, _
                                      MessageBoxIcon.Question, _
                                      MessageBoxDefaultButton.Button1, _
                                      0, "mspaint.chm", _
                                      HelpNavigator.Index)

注釈

メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。 パラメーターを owner 使用すると、ダイアログ ボックスの最上位ウィンドウと所有者として機能するインターフェイスを IWin32Window 実装する特定のオブジェクトを指定できます。

ユーザーが [ヘルプ] ボタンをクリックすると、 パラメーターで helpFilePath 指定されたヘルプ ファイルが開き、 パラメーターによって navigator 識別されるヘルプ コンテンツが表示されます。 メッセージ ボックス (またはアクティブフォーム) を所有するフォームもイベントを HelpRequested 受け取ります。

コンパイル済みヘルプ ファイルは、目次、インデックス、検索、ページ内のキーワード (keyword)リンクを提供します。 、、、または に対して、次の値をnavigatorIndexTableOfContentsFind使用できます。Topic

パラメーターの形式は helpFilePath C:\path\sample.chm または /folder/file.htm です。

こちらもご覧ください

適用対象

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

指定したオブジェクトの前に、指定したテキスト、キャプション、ボタン、アイコン、および既定のボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton) As DialogResult

パラメーター

owner
IWin32Window

モーダル ダイアログ ボックスを所有する IWin32Window の実装。

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

または

defaultButtonMessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

次のコード例では、 のこのオーバーロードShowでサポートされているオプションを使用して をMessageBox表示する方法を示します。 文字列変数 ServerNameが空であることを確認した後、この例では を表示 MessageBoxし、操作を取り消すオプションをユーザーに提供します。 メソッドの Show 戻り値が に Yes評価された場合、 を表示した MessageBox フォームは閉じられます。

private:
   void validateUserEntry2()
   {
      // 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, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, MessageBoxOptions::RightAlign );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }

private void validateUserEntry2()
{

    // 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;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 
            MessageBoxOptions.RightAlign);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry2()


    ' 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 = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)


        ' 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

注釈

パラメーターを owner 使用すると、ダイアログ ボックスの最上位ウィンドウと所有者として機能するインターフェイスを IWin32Window 実装する特定のオブジェクトを指定できます。 メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。

メッセージ ボックスには、最大 3 つのボタンを含めることができます。

こちらもご覧ください

適用対象

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

指定したオブジェクトの前に、指定したテキスト、キャプション、ボタン、およびアイコンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon) As DialogResult

パラメーター

owner
IWin32Window

モーダル ダイアログ ボックスを所有する IWin32Window の実装。

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

次のコード例では、 のこのオーバーロードShowでサポートされているオプションを使用して をMessageBox表示する方法を示します。 文字列変数 ServerNameが空であることを確認した後、この例では を表示 MessageBoxし、操作を取り消すオプションをユーザーに提供します。 メソッドの Show 戻り値が に Yes評価された場合、 を表示した MessageBox フォームは閉じられます。

private:
   void validateUserEntry4()
   {
      // 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, MessageBoxIcon::Question );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }
private void validateUserEntry4()
{

    // 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;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
            MessageBoxIcon.Question);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry4()

    ' 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 = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question)

        ' 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

注釈

パラメーターを owner 使用すると、ダイアログ ボックスの最上位ウィンドウと所有者として機能するインターフェイスを IWin32Window 実装する特定のオブジェクトを指定できます。 メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。

メッセージ ボックスには、最大 3 つのボタンを含めることができます。

こちらもご覧ください

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、および既定のボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton);
public static System.Windows.Forms.DialogResult Show (string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton);
public static System.Windows.Forms.DialogResult Show (string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

または

defaultButtonMessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

次のコード例では、 のこのオーバーロードShowでサポートされているオプションを使用して をMessageBox表示する方法を示します。 文字列変数 ServerName( ) が空であることを確認した後、この例では、操作を取り消すオプションをユーザーに提供する質問ボックス アイコンを含む が表示されます MessageBox 。 メソッドの Show 戻り値が に Yes評価された場合、 を表示した MessageBox フォームは閉じられます。

private:
   void validateUserEntry3()
   {
      // 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, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1 );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }
private void validateUserEntry3()
{

    // 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;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
        MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry3()

    ' 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 = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, _
            MessageBoxDefaultButton.Button1)

        ' 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

注釈

メッセージ ボックスには、最大 3 つのボタンを含めることができます。

こちらもご覧ください

適用対象

Show(IWin32Window, String, String, MessageBoxButtons)

指定したオブジェクトの前に、指定したテキスト、キャプション、およびボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons) As DialogResult

パラメーター

owner
IWin32Window

モーダル ダイアログ ボックスを所有する IWin32Window の実装。

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

次のコード例では、 のこのオーバーロードShowでサポートされているオプションを使用して をMessageBox表示する方法を示します。 文字列変数 ServerNameが空であることを確認した後、この例では を表示 MessageBoxし、操作を取り消すオプションをユーザーに提供します。 メソッドの Show 戻り値が に Yes評価された場合、 を表示した MessageBox フォームは閉じられます。

private:
   void validateUserEntry5()
   {
      // 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 validateUserEntry5()
{

    // 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;
        DialogResult result;

        // Displays the MessageBox.

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

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry5()

    ' 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 = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo)

        ' 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

注釈

パラメーターを owner 使用すると、ダイアログ ボックスの最上位ウィンドウと所有者として機能するインターフェイスを IWin32Window 実装する特定のオブジェクトを指定できます。 メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。

メッセージ ボックスには、最大 3 つのボタンを含めることができます。

こちらもご覧ください

適用対象

Show(String, String, MessageBoxButtons, MessageBoxIcon)

指定したテキスト、キャプション、ボタン、およびアイコンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon);
public static System.Windows.Forms.DialogResult Show (string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon);
public static System.Windows.Forms.DialogResult Show (string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

戻り値

DialogResult 値のいずれか 1 つ。

例外

指定した buttons パラメーターが、MessageBoxButtons のメンバーではありません。

- または -

指定した icon パラメーターが、MessageBoxIcon のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

次のコード例は、 イベントを処理する際の Show メソッドの 1 つを ComboBox.DropDown 示しています。 この例を実行するには、次のコードをフォームに貼り付け、フォームのコンストラクターまたはLoadメソッドから メソッドを呼び出InitializeComboBoxします。

internal:
   // Declare ComboBox1
   System::Windows::Forms::ComboBox^ ComboBox1;

private:
   // Initialize ComboBox1.
   void InitializeComboBox()
   {
      this->ComboBox1 = gcnew ComboBox;
      this->ComboBox1->Location = System::Drawing::Point( 128, 48 );
      this->ComboBox1->Name = "ComboBox1";
      this->ComboBox1->Size = System::Drawing::Size( 100, 21 );
      this->ComboBox1->TabIndex = 0;
      this->ComboBox1->Text = "Typical";
      array<String^>^ installs = {"Typical","Compact","Custom"};
      ComboBox1->Items->AddRange( installs );
      this->Controls->Add( this->ComboBox1 );
      
      // Hook up the event handler.
      this->ComboBox1->DropDown += gcnew System::EventHandler(
         this, &Form1::ComboBox1_DropDown );
   }

   // Handles the ComboBox1 DropDown event. If the user expands the  
   // drop-down box, a message box will appear, recommending the
   // typical installation.
   void ComboBox1_DropDown( Object^ sender, System::EventArgs^ e )
   {
      MessageBox::Show( "Typical installation is strongly recommended.",
         "Install information", MessageBoxButtons::OK,
         MessageBoxIcon::Information );
   }

// Declare ComboBox1.
internal System.Windows.Forms.ComboBox ComboBox1;

// Initialize ComboBox1.
private void InitializeComboBox()
{
    this.ComboBox1 = new ComboBox();
    this.ComboBox1.Location = new System.Drawing.Point(128, 48);
    this.ComboBox1.Name = "ComboBox1";
    this.ComboBox1.Size = new System.Drawing.Size(100, 21);
    this.ComboBox1.TabIndex = 0;
    this.ComboBox1.Text	= "Typical";
    string[] installs = new string[]{"Typical", "Compact", "Custom"};
    ComboBox1.Items.AddRange(installs);
    this.Controls.Add(this.ComboBox1);
    
    // Hook up the event handler.
    this.ComboBox1.DropDown +=  
        new System.EventHandler(ComboBox1_DropDown);
}

// Handles the ComboBox1 DropDown event. If the user expands the  
// drop-down box, a message box will appear, recommending the
// typical installation.
private void ComboBox1_DropDown(object sender, System.EventArgs e)
{
    MessageBox.Show("Typical installation is strongly recommended.", 
    "Install information", MessageBoxButtons.OK, 
        MessageBoxIcon.Information);
}

' Declare ComboBox1.
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox

' Initialize ComboBox1.
Private Sub InitializeComboBox()
    Me.ComboBox1 = New ComboBox
    Me.ComboBox1.Location = New System.Drawing.Point(128, 48)
    Me.ComboBox1.Name = "ComboBox1"
    Me.ComboBox1.Size = New System.Drawing.Size(100, 21)
    Me.ComboBox1.TabIndex = 0
    Me.ComboBox1.Text = "Typical"
    Dim installs() As String = New String() _
        {"Typical", "Compact", "Custom"}
    ComboBox1.Items.AddRange(installs)
    Me.Controls.Add(Me.ComboBox1)
End Sub

' Handles the ComboBox1 DropDown event. If the user expands the  
' drop-down box, a message box will appear, recommending the
' typical installation.
Private Sub ComboBox1_DropDown _ 
    (ByVal sender As Object, ByVal e As System.EventArgs) _ 
    Handles ComboBox1.DropDown
    MessageBox.Show("Typical installation is strongly recommended.", _
    "Install information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

注釈

メッセージ ボックスには、最大 3 つのボタンを含めることができます。

こちらもご覧ください

適用対象

Show(IWin32Window, String, String)

指定したオブジェクトの前に、指定したテキストとキャプションを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window owner, string text, string caption);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window? owner, string? text, string? caption);
static member Show : System.Windows.Forms.IWin32Window * string * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String) As DialogResult

パラメーター

owner
IWin32Window

モーダル ダイアログ ボックスを所有する IWin32Window の実装。

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

戻り値

DialogResult 値のいずれか 1 つ。

注釈

パラメーターを owner 使用すると、ダイアログ ボックスの最上位ウィンドウと所有者として機能するインターフェイスを IWin32Window 実装する特定のオブジェクトを指定できます。 メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。

既定では、メッセージ ボックスに [OK] ボタンが表示されます。

適用対象

Show(String, String, MessageBoxButtons)

指定したテキスト、キャプション、およびボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons);
public static System.Windows.Forms.DialogResult Show (string text, string caption, System.Windows.Forms.MessageBoxButtons buttons);
public static System.Windows.Forms.DialogResult Show (string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

戻り値

DialogResult 値のいずれか 1 つ。

例外

指定した buttons パラメーターが、MessageBoxButtons のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

次のコード例では、 のこのオーバーロードShowでサポートされているオプションを使用して をMessageBox表示する方法を示します。 文字列変数 ServerNameが空であることを確認した後、この例では を表示 MessageBoxし、操作を取り消すオプションをユーザーに提供します。 メソッドの Show 戻り値が に Yes評価された場合、 を表示した MessageBox フォームは閉じられます。

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

注釈

メッセージ ボックスには、最大 3 つのボタンを含めることができます。

こちらもご覧ください

適用対象

Show(IWin32Window, String)

指定したオブジェクトの前に、指定したテキストを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window owner, string text);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window? owner, string? text);
static member Show : System.Windows.Forms.IWin32Window * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String) As DialogResult

パラメーター

owner
IWin32Window

モーダル ダイアログ ボックスを所有する IWin32Window の実装。

text
String

メッセージ ボックスに表示するテキスト。

戻り値

DialogResult 値のいずれか 1 つ。

注釈

パラメーターを owner 使用すると、ダイアログ ボックスの最上位ウィンドウと所有者として機能するインターフェイスを IWin32Window 実装する特定のオブジェクトを指定できます。 メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。

既定では、メッセージ ボックスに [OK] ボタンが表示されます。 メッセージ ボックスには、タイトルにキャプションが含まれていません。

適用対象

Show(String, String)

指定したテキストとキャプションを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption);
public static System.Windows.Forms.DialogResult Show (string text, string caption);
public static System.Windows.Forms.DialogResult Show (string? text, string? caption);
static member Show : string * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

戻り値

DialogResult 値のいずれか 1 つ。

注釈

既定では、メッセージ ボックスに [OK] ボタンが表示されます。

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、およびオプションを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options);
public static System.Windows.Forms.DialogResult Show (string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options);
public static System.Windows.Forms.DialogResult Show (string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options);
static member Show : string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions -> System.Windows.Forms.DialogResult
Public Shared Function Show (text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions) As DialogResult

パラメーター

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

- または -

指定した defaultButton が、MessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例では、 のこのオーバーロードShowでサポートされているオプションを使用して をMessageBox表示する方法を示します。 文字列変数 ServerName( ) が空であることを確認した後、この例では、操作を取り消すオプションをユーザーに提供する質問ボックス アイコンを含む が表示されます MessageBox 。 この例では、 RightAlign 列挙体の メンバーを MessageBoxOptions 使用して、ダイアログ ボックスの右端にテキストを配置します。 メソッドの Show 戻り値が に Yes評価された場合、 を表示した MessageBox フォームは閉じられます。

private:
   void validateUserEntry2()
   {
      // 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, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, MessageBoxOptions::RightAlign );
         if ( result == ::DialogResult::Yes )
         {
            // Closes the parent form.
            this->Close();
         }
      }
   }

private void validateUserEntry2()
{

    // 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;
        DialogResult result;

        // Displays the MessageBox.

        result = MessageBox.Show(this, message, caption, buttons,
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 
            MessageBoxOptions.RightAlign);

        if(result == DialogResult.Yes)
        {

            // Closes the parent form.

            this.Close();
        }
    }
}
Private Sub ValidateUserEntry2()


    ' 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 = "No Server Name Specified"
        Dim Buttons As Integer = MessageBoxButtons.YesNo

        Dim Result As DialogResult

        'Displays a MessageBox using the Question icon and specifying the No button as the default.

        Result = MessageBox.Show(Me, Message, Caption, MessageBoxButtons.YesNo, _
            MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign)


        ' 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

注釈

メッセージ ボックスには、最大 3 つのボタンを含めることができます。

こちらもご覧ください

適用対象

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

指定したテキスト、キャプション、ボタン、アイコン、既定のボタン、オプション、および指定したヘルプ ファイル、HelpNavigator、およびヘルプ トピックを使用する [ヘルプ] ボタンを表示するメッセージ ボックスを表示します。

public:
 static System::Windows::Forms::DialogResult Show(System::Windows::Forms::IWin32Window ^ owner, System::String ^ text, System::String ^ caption, System::Windows::Forms::MessageBoxButtons buttons, System::Windows::Forms::MessageBoxIcon icon, System::Windows::Forms::MessageBoxDefaultButton defaultButton, System::Windows::Forms::MessageBoxOptions options, System::String ^ helpFilePath, System::Windows::Forms::HelpNavigator navigator, System::Object ^ param);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window owner, string text, string caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator, object param);
public static System.Windows.Forms.DialogResult Show (System.Windows.Forms.IWin32Window? owner, string? text, string? caption, System.Windows.Forms.MessageBoxButtons buttons, System.Windows.Forms.MessageBoxIcon icon, System.Windows.Forms.MessageBoxDefaultButton defaultButton, System.Windows.Forms.MessageBoxOptions options, string helpFilePath, System.Windows.Forms.HelpNavigator navigator, object? param);
static member Show : System.Windows.Forms.IWin32Window * string * string * System.Windows.Forms.MessageBoxButtons * System.Windows.Forms.MessageBoxIcon * System.Windows.Forms.MessageBoxDefaultButton * System.Windows.Forms.MessageBoxOptions * string * System.Windows.Forms.HelpNavigator * obj -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String, caption As String, buttons As MessageBoxButtons, icon As MessageBoxIcon, defaultButton As MessageBoxDefaultButton, options As MessageBoxOptions, helpFilePath As String, navigator As HelpNavigator, param As Object) As DialogResult

パラメーター

owner
IWin32Window

モーダル ダイアログ ボックスを所有する IWin32Window の実装。

text
String

メッセージ ボックスに表示するテキスト。

caption
String

メッセージ ボックスのタイトル バーに表示するテキスト。

buttons
MessageBoxButtons

メッセージ ボックスに表示するボタンを指定する MessageBoxButtons 値の 1 つ。

icon
MessageBoxIcon

メッセージ ボックスに表示するアイコンを指定する MessageBoxIcon 値の 1 つ。

defaultButton
MessageBoxDefaultButton

メッセージ ボックスの既定のボタンを指定する MessageBoxDefaultButton 値の 1 つ。

options
MessageBoxOptions

メッセージ ボックスで使用する表示オプションと関連付けオプションを指定する MessageBoxOptions 値の 1 つ。 既定値を使用する場合は、0 を渡します。

helpFilePath
String

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ ファイルのパスと名前。

navigator
HelpNavigator

HelpNavigator 値のいずれか 1 つ。

param
Object

ユーザーが [ヘルプ] ボタンをクリックしたときに表示されるヘルプ トピックの数値 ID。

戻り値

DialogResult 値のいずれか 1 つ。

例外

buttonsMessageBoxButtons のメンバーではありません。

または

iconMessageBoxIcon のメンバーではありません。

- または -

指定した defaultButton が、MessageBoxDefaultButton のメンバーではありません。

ユーザー対話モード以外のモードで実行されているプロセスで、MessageBox を表示しようとしました。 このモードは、UserInteractive プロパティで指定されています。

options に、DefaultDesktopOnlyServiceNotification が両方指定されています。

- または -

buttons に、無効な MessageBoxButtons の組み合わせが指定されています。

次のコード例は、メイン ウィンドウに親されたメッセージ ボックスを表示する方法を示しています。 メッセージ ボックスに [ヘルプ] ボタンが表示されます。 ユーザーが [ヘルプ] ボタンをクリックすると、Mspaint.chmヘルプ ファイルが開き、[ヘルプ インデックス] タブと、キーワード (keyword)によってovals識別されたトピックが表示されます。 この例では、ヘルプ ファイルが Mspaint.chm インストールされている必要があります。

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::ComponentModel;
using namespace System::Windows::Forms;
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file, 
// shows index with the "ovals" keyword selected, and displays the
// associated topic.
System::Windows::Forms::DialogResult r6 = MessageBox::Show( this, "Message with Help file and Help navigator with additional parameter.", "Help Caption", MessageBoxButtons::OK, MessageBoxIcon::Question, MessageBoxDefaultButton::Button1, (MessageBoxOptions)0, "mspaint.chm", HelpNavigator::KeywordIndex, "ovals" );
// Display message box parented to the main form. 
// The Help button opens the Mspaint.chm Help file, 
// shows index with the "ovals" keyword selected, and displays the
// associated topic.
DialogResult r6 = MessageBox.Show (this, 
                                   "Message with Help file and Help navigator with additional parameter.", 
                                   "Help Caption", MessageBoxButtons.OK, 
                                   MessageBoxIcon.Question, 
                                   MessageBoxDefaultButton.Button1, 
                                   0, "mspaint.chm", 
                                   HelpNavigator.KeywordIndex, "ovals");
' Display message box parented to the main form. 
' The Help button opens the Mspaint.chm Help file, 
' shows index with the "ovals" keyword selected, and displays the
' associated topic.
Dim r6 As DialogResult = MessageBox.Show(Me, _
                                   "Message with Help file and Help navigator with additional parameter.", _
                                   "Help Caption", MessageBoxButtons.OK, _
                                   MessageBoxIcon.Question, _
                                   MessageBoxDefaultButton.Button1, _
                                   0, "mspaint.chm", _
                                   HelpNavigator.KeywordIndex, "ovals")

注釈

メッセージ ボックスはモーダル ダイアログ ボックスです。つまり、モーダル フォーム上のオブジェクトを除き、入力 (キーボードまたはマウス クリック) は発生しません。 プログラムは、別のフォームへの入力を行う前に、モーダル フォームを非表示または閉じる必要があります (通常、何らかのユーザー アクションに応答)。 パラメーターを owner 使用すると、ダイアログ ボックスの最上位ウィンドウと所有者として機能するインターフェイスを IWin32Window 実装する特定のオブジェクトを指定できます。

ユーザーが [ヘルプ] ボタンをクリックすると、 パラメーターで helpFilePath 指定されたヘルプ ファイルが開き、 パラメーターによって navigator 識別されるヘルプ コンテンツが表示されます。 メッセージ ボックス (またはアクティブフォーム) を所有するフォームもイベントを HelpRequested 受け取ります。

コンパイルされたヘルプ ファイルは、目次、インデックス、検索、ページ内のキーワード (keyword)リンクを提供します。 、、、または に対して、次の値をnavigatorIndexTableOfContentsFind使用できます。Topic

を使用 param して、コマンドをさらに Topic 絞り込むことができます。 パラメーターで navigator 指定された値が TableOfContents、、 Indexまたは Findの場合、この値は である null必要があります。 パラメーターが を参照Topicしているnavigator場合、この値は、表示するトピックの数値を含むオブジェクトを参照する必要があります。

パラメーターの形式は helpFilePath C:\path\sample.chm または /folder/file.htm です。

こちらもご覧ください

適用対象