MessageBox.Show Méthode
Définition
Affiche une boîte de message.Displays a message box.
Surcharges
Show(String) |
Affiche un message avec le texte spécifié.Displays a message box with specified text. |
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String) |
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié et le mot clé d'aide.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file and Help keyword. |
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object) |
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié, du |
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String) |
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file. |
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator) |
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié et de |
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String) |
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié et le mot clé d'aide.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file and Help keyword. |
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions) |
Affiche, devant l'objet spécifié, un message contenant le texte, la légende, les boutons, l'icône, le bouton par défaut et les options spécifiés.Displays a message box in front of the specified object and with the specified text, caption, buttons, icon, default button, and options. |
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String) |
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file. |
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, Boolean) |
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide spécifiés.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button. |
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator) |
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié et de |
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton) |
Affiche un message contenant le texte, la légende, les boutons, l'icône et le bouton par défaut spécifiés devant l'objet spécifié.Displays a message box in front of the specified object and with the specified text, caption, buttons, icon, and default button. |
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon) |
Affiche un message contenant le texte, la légende, les boutons et l'icône spécifiés devant l'objet spécifié.Displays a message box in front of the specified object and with the specified text, caption, buttons, and icon. |
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton) |
Affiche un message avec le texte, la légende, les boutons, l'icône et le bouton par défaut spécifiés.Displays a message box with the specified text, caption, buttons, icon, and default button. |
Show(IWin32Window, String, String, MessageBoxButtons) |
Affiche un message contenant le texte, la légende et les boutons spécifiés devant l'objet spécifié.Displays a message box in front of the specified object and with the specified text, caption, and buttons. |
Show(String, String, MessageBoxButtons, MessageBoxIcon) |
Affiche un message avec le texte, la légende, les boutons et l'icône spécifiés.Displays a message box with specified text, caption, buttons, and icon. |
Show(IWin32Window, String, String) |
Affiche un message contenant le texte et la légende spécifiés devant l'objet spécifié.Displays a message box in front of the specified object and with the specified text and caption. |
Show(String, String, MessageBoxButtons) |
Affiche un message avec le texte, la légende et les boutons spécifiés.Displays a message box with specified text, caption, and buttons. |
Show(IWin32Window, String) |
Affiche un message contenant le texte spécifié devant l'objet spécifié.Displays a message box in front of the specified object and with the specified text. |
Show(String, String) |
Affiche un message avec le texte et la légende spécifiés.Displays a message box with specified text and caption. |
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions) |
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut et les options spécifiés.Displays a message box with the specified text, caption, buttons, icon, default button, and options. |
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object) |
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié, du |
Show(String)
Affiche un message avec le texte spécifié.Displays a message box with specified text.
public:
static System::Windows::Forms::DialogResult Show(System::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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exemples
L’exemple de code suivant affiche une boîte de message simple.The following code example displays a simple message box.
private void DisplayMessageBoxText()
{
MessageBox.Show("Hello, world.");
}
Private Sub DisplayMessageBoxText()
MessageBox.Show("Hello, world.")
End Sub
Remarques
Par défaut, la boîte de message affiche un bouton OK .By default, the message box displays an OK button. La boîte de message ne contient pas de légende dans le titre.The message box does not contain a caption in the title.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées définissent cette propriété.for safe subwindows to set this property. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String)
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié et le mot clé d'aide.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file and Help keyword.
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);
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
Paramètres
- owner
- IWin32Window
Implémentation de IWin32Window auquel appartiendra la boîte de dialogue modale.An implementation of IWin32Window that will own the modal dialog box.
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
- helpFilePath
- String
Chemin d'accès et nom du fichier d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The path and name of the Help file to display when the user clicks the Help button.
- keyword
- String
Mot clé d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The Help keyword to display when the user clicks the Help button.
Retours
Une des valeurs de l'objet DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
ou-or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
ou-or-
Le defaultButton
spécifié n'est pas un membre de MessageBoxDefaultButton.The defaultButton
specified is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
- ou --or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher une boîte de message apparenté à la fenêtre principale.The following code example demonstrates how to show a message box parented to the main window. La boîte de message affiche un bouton aide.The message box displays a Help button. Quand l’utilisateur clique sur le bouton aide Mspaint.chm
, le fichier d’aide s’ouvre et la rubrique mspaint.chm::/paint_brush.htm
identifiée par le mot clé s’affiche.When the user clicks the Help button, the Mspaint.chm
Help file is opened and the topic identified by the mspaint.chm::/paint_brush.htm
keyword is displayed. L’exemple requiert l’installation Mspaint.chm
du fichier d’aide.The example requires that the Mspaint.chm
Help file is installed.
#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")
Remarques
Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur. Vous pouvez utiliser le owner
paramètre pour spécifier un objet particulier, qui implémente l' IWin32Window interface, qui fera office de propriétaire de niveau supérieur de la boîte de dialogue.You can use the owner
parameter to specify a particular object, which implements the IWin32Window interface, that will serve as the dialog box's top-level owner.
Quand l’utilisateur clique sur le bouton aide, le fichier d’aide helpFilePath
spécifié dans le paramètre s’ouvre et la rubrique de mot keyword
clé d’aide identifiée par le paramètre s’affiche.When the user clicks the Help button, the Help file specified in the helpFilePath
parameter is opened and the Help keyword topic identified by the keyword
parameter is displayed. Le formulaire qui possède la boîte de message (ou le formulaire actif) reçoit également HelpRequested l’événement.The form that owns the message box (or the active form) also receives the HelpRequested event.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
WebPermission
pour accéder à un fichier d’aide HTML par le biais d’une requête HTTP.to access a HTML help file through a HTTP request. Énumération associée:ConnectAssociated enumeration: Connect
SecurityPermission
pour accéder à un fichier d’aide HTML qui n’est pas pris en charge à partir d’un serveur HTTP.to access a HTML help file not served from a HTTP server. Énumération associée:UnmanagedCodeAssociated enumeration: UnmanagedCode
Voir aussi
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object)
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié, du HelpNavigator
et de la rubrique d'aide.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file, HelpNavigator
, and Help topic.
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);
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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
- helpFilePath
- String
Chemin d'accès et nom du fichier d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The path and name of the Help file to display when the user clicks the Help button.
- navigator
- HelpNavigator
Une des valeurs de l'objet HelpNavigator.One of the HelpNavigator values.
- param
- Object
ID numérique de la rubrique d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The numeric ID of the Help topic to display when the user clicks the Help button.
Retours
Une des valeurs de l'objet DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
ou-or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
ou-or-
Le defaultButton
spécifié n'est pas un membre de MessageBoxDefaultButton.The defaultButton
specified is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
ou-or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher une boîte de message avec un bouton d’aide.The following code example demonstrates how to show a message box with a Help button. Quand l’utilisateur clique sur le bouton aide Mspaint.chm
, le fichier d’aide s’ouvre et l’onglet Index de l’aide et ovals
la rubrique identifiée par le mot clé sont affichés.When the user clicks the Help button, the Mspaint.chm
Help file is opened and the Help index tab and the topic identified by the ovals
keyword are displayed. L’exemple requiert l’installation Mspaint.chm
du fichier d’aide.The example requires that the Mspaint.chm
Help file is installed.
#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")
Remarques
Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Quand l’utilisateur clique sur le bouton aide, le fichier d’aide helpFilePath
spécifié dans le paramètre s’ouvre et le contenu d' navigator
aide identifié par le paramètre s’affiche.When the user clicks the Help button, the Help file specified in the helpFilePath
parameter is opened and the Help content identified by the navigator
parameter is displayed. Le formulaire qui possède la boîte de message (ou le formulaire actif) reçoit également HelpRequested l’événement.The form that owns the message box (or the active form) also receives the HelpRequested event.
Les fichiers d’aide compilés fournissent des tables de matières, d’index, de recherche et de mots clés dans les pages.Compiled help files provide table of contents, index, search, and keyword links in pages. Vous pouvez utiliser les valeurs suivantes pour navigator
: TableOfContents, Find, Indexou Topic.You can use the following values for navigator
: TableOfContents, Find, Index, or Topic.
Vous pouvez utiliser param
pour fournir une affination supplémentaire Topic de la commande.You can use param
to provide further refinement of the Topic command. Si la valeur spécifiée dans le navigator
paramètre est TableOfContents, Indexou Find, cette valeur doit être null
.If the value specified in the navigator
parameter is TableOfContents, Index, or Find, this value should be null
. Si le navigator
paramètre fait Topicréférence à, cette valeur doit faire référence à un objet qui contient la valeur numérique de la rubrique à afficher.If the navigator
parameter references Topic, this value should reference an object that contains the numeric value of the topic to display.
Le helpFilePath
paramètre peut être de la forme "c:\path\sample.chm" ou/folder/file.htm.The helpFilePath
parameter can be of the form C:\path\sample.chm or /folder/file.htm.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
WebPermission
pour accéder à un fichier d’aide HTML par le biais d’une requête HTTP.to access a HTML help file through a HTTP request. Énumération associée:ConnectAssociated enumeration: Connect
SecurityPermission
pour accéder à un fichier d’aide HTML qui n’est pas pris en charge à partir d’un serveur HTTP.to access a HTML help file not served from a HTTP server. Énumération associée:UnmanagedCodeAssociated enumeration: UnmanagedCode
Voir aussi
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String)
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file.
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);
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
Paramètres
- owner
- IWin32Window
Implémentation de IWin32Window auquel appartiendra la boîte de dialogue modale.An implementation of IWin32Window that will own the modal dialog box.
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
- helpFilePath
- String
Chemin d'accès et nom du fichier d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The path and name of the Help file to display when the user clicks the Help button.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
- ou --or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
ou-or-
Le defaultButton
spécifié n'est pas un membre de MessageBoxDefaultButton.The defaultButton
specified is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
ou-or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher une boîte de message qui est apparentée au formulaire principal.The following code example demonstrates how to show a message box that parented to the main form. La boîte de message affiche un bouton aide.The message box displays a Help button. Quand l’utilisateur clique sur le bouton aide Mspaint.chm
, le fichier d’aide est ouvert.When the user clicks the Help button, the Mspaint.chm
Help file is opened. L’exemple requiert l’installation Mspaint.chm
du fichier d’aide.The example requires that the Mspaint.chm
Help file is installed.
#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")
Remarques
Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur. Vous pouvez utiliser le owner
paramètre pour spécifier un objet particulier, qui implémente l' IWin32Window interface, qui servira de fenêtre de niveau supérieur et de propriétaire de la boîte de dialogue.You can use the owner
parameter to specify a particular object, which implements the IWin32Window interface, that will serve as the dialog box's top-level window and owner.
Quand l’utilisateur clique sur le bouton aide, le fichier d’aide helpFilePath
spécifié dans le paramètre est ouvert.When the user clicks the Help button, the Help file specified in the helpFilePath
parameter is opened. Le formulaire qui possède la boîte de message (ou le formulaire actif) reçoit également HelpRequested l’événement.The form that owns the message box (or the active form) also receives the HelpRequested event.
Le helpFilePath
paramètre peut être de la forme "c:\path\sample.chm" ou/folder/file.htm.The helpFilePath
parameter can be of the form C:\path\sample.chm or /folder/file.htm.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
WebPermission
pour accéder à un fichier d’aide HTML par le biais d’une requête HTTP.to access a HTML help file through a HTTP request. Énumération associée:ConnectAssociated enumeration: Connect
SecurityPermission
pour accéder à un fichier d’aide HTML qui n’est pas pris en charge à partir d’un serveur HTTP.to access a HTML help file not served from a HTTP server. Énumération associée:UnmanagedCodeAssociated enumeration: UnmanagedCode
Voir aussi
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator)
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié et de HelpNavigator
.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file and 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);
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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
- helpFilePath
- String
Chemin d'accès et nom du fichier d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The path and name of the Help file to display when the user clicks the Help button.
- navigator
- HelpNavigator
Une des valeurs de HelpNavigator.One of the HelpNavigator values.
Retours
Une des valeurs de l'objet DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
- ou --or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
- ou --or-
Le defaultButton
spécifié n'est pas un membre de MessageBoxDefaultButton.The defaultButton
specified is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
- ou --or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher une boîte de message avec un bouton d’aide.The following code example demonstrates how to show a message box with a Help button. Quand l’utilisateur clique sur le bouton aide Mspaint.chm
, le fichier d’aide s’ouvre et l’onglet Index de l’aide s’affiche.When the user clicks the Help button, the Mspaint.chm
Help file is opened and the Help index tab is displayed. L’exemple requiert l’installation Mspaint.chm
du fichier d’aide.The example requires that the Mspaint.chm
Help file is installed.
#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)
Remarques
Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Quand l’utilisateur clique sur le bouton aide, le fichier d’aide helpFilePath
spécifié dans le paramètre s’ouvre et le contenu d' navigator
aide identifié par le paramètre s’affiche.When the user clicks the Help button, the help file specified in the helpFilePath
parameter is opened and the Help content identified by the navigator
parameter is displayed. Le formulaire qui possède la boîte de message (ou le formulaire actif) reçoit également HelpRequested l’événement.The form that owns the message box (or the active form) also receives the HelpRequested event.
Les fichiers d’aide compilés fournissent des tables de matières, d’index, de recherche et de mots clés dans les pages.Compiled Help files provide table of contents, index, search, and keyword links in pages. Vous pouvez utiliser les valeurs suivantes pour navigator
: TableOfContents, Find, Indexou Topic.You can use the following values for navigator
: TableOfContents, Find, Index, or Topic.
Le helpFilePath
paramètre peut être de la forme "c:\path\sample.chm" ou/folder/file.htm.The helpFilePath
parameter can be of the form C:\path\sample.chm or /folder/file.htm.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
WebPermission
pour accéder à un fichier d’aide HTML par le biais d’une requête HTTP.to access a HTML help file through a HTTP request. Énumération associée:ConnectAssociated enumeration: Connect
SecurityPermission
pour accéder à un fichier d’aide HTML qui n’est pas pris en charge à partir d’un serveur HTTP.to access a HTML help file not served from a HTTP server. Énumération associée:UnmanagedCodeAssociated enumeration: UnmanagedCode
Voir aussi
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, String)
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié et le mot clé d'aide.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file and Help keyword.
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);
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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
- helpFilePath
- String
Chemin d'accès et nom du fichier d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The path and name of the Help file to display when the user clicks the Help button.
- keyword
- String
Mot clé d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The Help keyword to display when the user clicks the Help button.
Retours
Une des valeurs de l'objet DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
ou-or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
ou-or-
Le defaultButton
spécifié n'est pas un membre de MessageBoxDefaultButton.The defaultButton
specified is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
- ou --or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher une boîte de message avec un bouton d’aide.The following code example demonstrates how to show a message box with a Help button. Quand l’utilisateur clique sur le bouton aide Mspaint.chm
, le fichier d’aide s’ouvre et la rubrique mspaint.chm::/paint_brush.htm
identifiée par le mot clé s’affiche.When the user clicks the Help button, the Mspaint.chm
Help file is opened and the topic identified by the mspaint.chm::/paint_brush.htm
keyword is displayed. L’exemple requiert l’installation Mspaint.chm
du fichier d’aide.The example requires that the Mspaint.chm
Help file is installed.
#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")
Remarques
Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Quand l’utilisateur clique sur le bouton aide, le fichier d’aide helpFilePath
spécifié dans le paramètre s’ouvre et la rubrique de mot keyword
clé d’aide identifiée par le paramètre s’affiche.When the user clicks the Help button, the Help file specified in the helpFilePath
parameter is opened and the Help keyword topic identified by the keyword
parameter is displayed. Le formulaire qui possède la boîte de message (ou le formulaire actif) reçoit également HelpRequested l’événement.The form that owns the message box (or the active form) also receives the HelpRequested event.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
WebPermission
pour accéder à un fichier d’aide HTML par le biais d’une requête HTTP.to access a HTML help file through a HTTP request. Énumération associée:ConnectAssociated enumeration: Connect
SecurityPermission
pour accéder à un fichier d’aide HTML qui n’est pas pris en charge à partir d’un serveur HTTP.to access a HTML help file not served from a HTTP server. Énumération associée:UnmanagedCodeAssociated enumeration: UnmanagedCode
Voir aussi
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions)
Affiche, devant l'objet spécifié, un message contenant le texte, la légende, les boutons, l'icône, le bouton par défaut et les options spécifiés.Displays a message box in front of the specified object and with the specified text, caption, buttons, icon, default button, and options.
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);
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
Paramètres
- owner
- IWin32Window
Implémentation de IWin32Window auquel appartiendra la boîte de dialogue modale.An implementation of IWin32Window that will own the modal dialog box.
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values the specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
ou-or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
ou-or-
defaultButton
n’est pas membre de MessageBoxDefaultButtondefaultButton
is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
ou-or-
options
a spécifié DefaultDesktopOnly ou ServiceNotification et a indiqué une valeur dans le paramètre owner
.options
specified DefaultDesktopOnly or ServiceNotification and specified a value in the owner
parameter. Ces deux options ne doivent être utilisées que pour appeler la version de cette méthode qui ne prend pas un paramètre owner
.These two options should be used only if you invoke the version of this method that does not take an owner
parameter.
ou-or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher un MessageBox avec les options prises en charge par cette Showsurcharge de.The following code example demonstrates how to display a MessageBox with the options supported by this overload of Show. Après avoir vérifié qu’une variable de chaîne ServerName
,, est vide, l’exemple affiche MessageBoxun, offrant à l’utilisateur la possibilité d’annuler l’opération.After verifying that a string variable, ServerName
, is empty, the example displays a MessageBox, offering the user the option to cancel the operation. Si la Show valeur de retour de la méthode MessageBox est Yeségale à, le formulaire qui affichait est fermé.If the Show method's return value evaluates to Yes, the form that displayed the MessageBox is closed.
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
Remarques
Vous pouvez utiliser le owner
paramètre pour spécifier un objet particulier, qui implémente l' IWin32Window interface, qui servira de fenêtre de niveau supérieur et de propriétaire de la boîte de dialogue.You can use the owner
parameter to specify a particular object, which implements the IWin32Window interface, that will serve as the dialog box's top-level window and owner. Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Vous pouvez avoir un maximum de trois boutons sur la boîte de message.You can have a maximum of three buttons on the message box.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Voir aussi
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String)
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file.
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);
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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
- helpFilePath
- String
Chemin d'accès et nom du fichier d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The path and name of the Help file to display when the user clicks the Help button.
Retours
Une des valeurs de l'objet DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
ou-or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
ou-or-
Le defaultButton
spécifié n'est pas un membre de MessageBoxDefaultButton.The defaultButton
specified is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
- ou --or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher une boîte de message avec un bouton d’aide.The following code example demonstrates how to show a message box with a Help button. Quand l’utilisateur clique sur le bouton aide Mspaint.chm
, le fichier d’aide est ouvert.When the user clicks the Help button, the Mspaint.chm
Help file is opened. L’exemple requiert l’installation Mspaint.chm
du fichier d’aide.The example requires that the Mspaint.chm
Help file is installed.
#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")
Remarques
Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Quand l’utilisateur clique sur le bouton aide, le fichier d' helpFilePath
aide spécifié dans le paramètre est ouvert.When the user clicks Help button, the Help file specified in the helpFilePath
parameter is opened. Le formulaire qui possède la boîte de message (ou le formulaire actif) reçoit également HelpRequested l’événement.The form that owns the message box (or the active form) also receives the HelpRequested event.
Le helpFilePath
paramètre peut être de la forme "c:\path\sample.chm" ou/folder/file.htm.The helpFilePath
parameter can be of the form C:\path\sample.chm or /folder/file.htm.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
WebPermission
pour accéder à un fichier d’aide HTML par le biais d’une requête HTTP.to access a HTML help file through a HTTP request. Énumération associée:ConnectAssociated enumeration: Connect
SecurityPermission
pour accéder à un fichier d’aide HTML qui n’est pas pris en charge à partir d’un serveur HTTP.to access a HTML help file not served from a HTTP server. Énumération associée:UnmanagedCodeAssociated enumeration: UnmanagedCode
Voir aussi
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, Boolean)
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide spécifiés.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button.
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);
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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
- displayHelpButton
- Boolean
true
pour afficher le bouton Aide ; sinon, false
.true
to show the Help button; otherwise, false
. La valeur par défaut est false
.The default is false
.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
- ou --or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
ou-or-
Le defaultButton
spécifié n'est pas un membre de MessageBoxDefaultButton.The defaultButton
specified is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
- ou --or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher une boîte de message avec un bouton d’aide, Control.HelpRequested gérer l’événement et afficher une fenêtre d’aide personnalisée en réponse à l’événement.The following code example demonstrates how to show a message box with a Help button, handle the Control.HelpRequested event, and show a custom help window in response to the event.
#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
Remarques
Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Quand l’utilisateur clique sur le bouton aide, le formulaire qui possède la boîte de message (ou le formulaire actif HelpRequested ) reçoit l’événement.When the user clicks the Help button, the form that owns the message box (or the active form) receives the HelpRequested event. Gérez l' HelpRequested événement pour exécuter des actions d’aide personnalisées.Handle the HelpRequested event to perform custom Help actions.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Voir aussi
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator)
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié et de HelpNavigator
.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file and 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);
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
Paramètres
- owner
- IWin32Window
Implémentation de IWin32Window auquel appartiendra la boîte de dialogue modale.An implementation of IWin32Window that will own the modal dialog box.
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
- helpFilePath
- String
Chemin d'accès et nom du fichier d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The path and name of the Help file to display when the user clicks the Help button.
- navigator
- HelpNavigator
Une des valeurs de l'objet HelpNavigator.One of the HelpNavigator values.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
ou-or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
- ou --or-
Le defaultButton
spécifié n'est pas un membre de MessageBoxDefaultButton.The defaultButton
specified is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
- ou --or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher une boîte de message apparenté à la fenêtre principale.The following code example demonstrates how to show a message box parented to the main window. La boîte de message affiche un bouton aide.The message box displays a Help button. Quand l’utilisateur clique sur le bouton aide Mspaint.chm
, le fichier d’aide s’ouvre et l’onglet Index de l’aide s’affiche.When the user clicks the Help button, the Mspaint.chm
Help file is opened and the Help index tab is displayed. L’exemple requiert l’installation Mspaint.chm
du fichier d’aide.The example requires that the Mspaint.chm
Help file is installed.
#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)
Remarques
Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur. Vous pouvez utiliser le owner
paramètre pour spécifier un objet particulier, qui implémente l' IWin32Window interface, qui servira de fenêtre de niveau supérieur et de propriétaire de la boîte de dialogue.You can use the owner
parameter to specify a particular object, which implements the IWin32Window interface, that will serve as the dialog box's top-level window and owner.
Quand l’utilisateur clique sur le bouton aide, le fichier d’aide helpFilePath
spécifié dans le paramètre s’ouvre et le contenu d' navigator
aide identifié par le paramètre s’affiche.When the user clicks the Help button, the Help file specified in the helpFilePath
parameter is opened and the Help content identified by the navigator
parameter is displayed. Le formulaire qui possède la boîte de message (ou le formulaire actif) reçoit également HelpRequested l’événement.The form that owns the message box (or the active form) also receives the HelpRequested event.
Les fichiers d’aide compilés fournissent des tables de matières, d’index, de recherche et de mots clés dans les pages.Compiled Help files provide table of contents, index, search, and keyword links in pages. Vous pouvez utiliser les valeurs suivantes pour navigator
: TableOfContents, Find, Indexou Topic.You can use the following values for navigator
: TableOfContents, Find, Index, or Topic.
Le helpFilePath
paramètre peut être de la forme "c:\path\sample.chm" ou/folder/file.htm.The helpFilePath
parameter can be of the form C:\path\sample.chm or /folder/file.htm.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
WebPermission
pour accéder à un fichier d’aide HTML par le biais d’une requête HTTP.to access a HTML help file through a HTTP request. Énumération associée:ConnectAssociated enumeration: Connect
SecurityPermission
pour accéder à un fichier d’aide HTML qui n’est pas pris en charge à partir d’un serveur HTTP.to access a HTML help file not served from a HTTP server. Énumération associée:UnmanagedCodeAssociated enumeration: UnmanagedCode
Voir aussi
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)
Affiche un message contenant le texte, la légende, les boutons, l'icône et le bouton par défaut spécifiés devant l'objet spécifié.Displays a message box in front of the specified object and with the specified text, caption, buttons, icon, and default button.
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);
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
Paramètres
- owner
- IWin32Window
Implémentation de IWin32Window auquel appartiendra la boîte de dialogue modale.An implementation of IWin32Window that will own the modal dialog box.
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
ou-or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
- ou --or-
defaultButton
n’est pas membre de MessageBoxDefaultButtondefaultButton
is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
Exemples
L’exemple de code suivant montre comment afficher un MessageBox avec les options prises en charge par cette Showsurcharge de.The following code example demonstrates how to display a MessageBox with the options supported by this overload of Show. Après avoir vérifié qu’une variable de chaîne ServerName
,, est vide, l’exemple affiche MessageBoxun, offrant à l’utilisateur la possibilité d’annuler l’opération.After verifying that a string variable, ServerName
, is empty, the example displays a MessageBox, offering the user the option to cancel the operation. Si la Show valeur de retour de la méthode MessageBox est Yeségale à, le formulaire qui affichait est fermé.If the Show method's return value evaluates to Yes, the form that displayed the MessageBox is closed.
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
Remarques
Vous pouvez utiliser le owner
paramètre pour spécifier un objet particulier, qui implémente l' IWin32Window interface, qui servira de fenêtre de niveau supérieur et de propriétaire de la boîte de dialogue.You can use the owner
parameter to specify a particular object, which implements the IWin32Window interface, that will serve as the dialog box's top-level window and owner. Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Vous pouvez avoir un maximum de trois boutons sur la boîte de message.You can have a maximum of three buttons on the message box.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Voir aussi
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon)
Affiche un message contenant le texte, la légende, les boutons et l'icône spécifiés devant l'objet spécifié.Displays a message box in front of the specified object and with the specified text, caption, buttons, and icon.
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);
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
Paramètres
- owner
- IWin32Window
Implémentation de IWin32Window auquel appartiendra la boîte de dialogue modale.An implementation of IWin32Window that will own the modal dialog box.
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
ou-or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
Exemples
L’exemple de code suivant montre comment afficher un MessageBox avec les options prises en charge par cette Showsurcharge de.The following code example demonstrates how to display a MessageBox with the options supported by this overload of Show. Après avoir vérifié qu’une variable de chaîne ServerName
,, est vide, l’exemple affiche MessageBoxun, offrant à l’utilisateur la possibilité d’annuler l’opération.After verifying that a string variable, ServerName
, is empty, the example displays a MessageBox, offering the user the option to cancel the operation. Si la Show valeur de retour de la méthode MessageBox est Yeségale à, le formulaire qui affichait est fermé.If the Show method's return value evaluates to Yes, the form that displayed the MessageBox is closed.
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
Remarques
Vous pouvez utiliser le owner
paramètre pour spécifier un objet particulier, qui implémente l' IWin32Window interface, qui servira de fenêtre de niveau supérieur et de propriétaire de la boîte de dialogue.You can use the owner
parameter to specify a particular object, which implements the IWin32Window interface, that will serve as the dialog box's top-level window and owner. Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Vous pouvez avoir un maximum de trois boutons sur la boîte de message.You can have a maximum of three buttons on the message box.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Voir aussi
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton)
Affiche un message avec le texte, la légende, les boutons, l'icône et le bouton par défaut spécifiés.Displays a message box with the specified text, caption, buttons, icon, and default button.
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);
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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
ou-or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
- ou --or-
defaultButton
n’est pas membre de MessageBoxDefaultButtondefaultButton
is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
Exemples
L’exemple de code suivant montre comment afficher un MessageBox avec les options prises en charge par cette Showsurcharge de.The following code example demonstrates how to display a MessageBox with the options supported by this overload of Show. Après avoir vérifié qu’une variable de chaîne ServerName
,, est vide, l’exemple affiche MessageBox une icône avec une zone de question, offrant à l’utilisateur la possibilité d’annuler l’opération.After verifying that a string variable, ServerName
, is empty, the example displays a MessageBox with a question box icon, offering the user the option to cancel the operation. Si la Show valeur de retour de la méthode MessageBox est Yeségale à, le formulaire qui affichait est fermé.If the Show method's return value evaluates to Yes, the form that displayed the MessageBox is closed.
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
Remarques
Vous pouvez avoir un maximum de trois boutons sur la boîte de message.You can have a maximum of three buttons on the message box.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Voir aussi
Show(IWin32Window, String, String, MessageBoxButtons)
Affiche un message contenant le texte, la légende et les boutons spécifiés devant l'objet spécifié.Displays a message box in front of the specified object and with the specified text, caption, and buttons.
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);
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
Paramètres
- owner
- IWin32Window
Implémentation de IWin32Window auquel appartiendra la boîte de dialogue modale.An implementation of IWin32Window that will own the modal dialog box.
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
Exemples
L’exemple de code suivant montre comment afficher un MessageBox avec les options prises en charge par cette Showsurcharge de.The following code example demonstrates how to display a MessageBox with the options supported by this overload of Show. Après avoir vérifié qu’une variable de chaîne ServerName
,, est vide, l’exemple affiche MessageBoxun, offrant à l’utilisateur la possibilité d’annuler l’opération.After verifying that a string variable, ServerName
, is empty, the example displays a MessageBox, offering the user the option to cancel the operation. Si la Show valeur de retour de la méthode MessageBox est Yeségale à, le formulaire qui affichait est fermé.If the Show method's return value evaluates to Yes, the form that displayed the MessageBox is closed.
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
Remarques
Vous pouvez utiliser le owner
paramètre pour spécifier un objet particulier, qui implémente l' IWin32Window interface, qui servira de fenêtre de niveau supérieur et de propriétaire de la boîte de dialogue.You can use the owner
parameter to specify a particular object, which implements the IWin32Window interface, that will serve as the dialog box's top-level window and owner. Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Vous pouvez avoir un maximum de trois boutons sur la boîte de message.You can have a maximum of three buttons on the message box.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Voir aussi
Show(String, String, MessageBoxButtons, MessageBoxIcon)
Affiche un message avec le texte, la légende, les boutons et l'icône spécifiés.Displays a message box with specified text, caption, buttons, and icon.
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);
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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
Le paramètre buttons
spécifié n'est pas un membre de MessageBoxButtons.The buttons
parameter specified is not a member of MessageBoxButtons.
ou-or-
Le paramètre icon
spécifié n'est pas un membre de MessageBoxIcon.The icon
parameter specified is not a member of MessageBoxIcon.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
Exemples
L’exemple de code suivant illustre l’une Show des méthodes lors de ComboBox.DropDown la gestion de l’événement.The following code example demonstrates one of the Show methods when handling the ComboBox.DropDown event. Pour exécuter l’exemple, collez le code suivant dans un formulaire et appelez InitializeComboBox
la méthode à partir de la méthode Load
ou du constructeur du formulaire.To run the example, paste the following code in a form and call the InitializeComboBox
method from the form's constructor or Load
method.
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
Remarques
Vous pouvez avoir un maximum de trois boutons sur la boîte de message.You can have a maximum of three buttons on the message box.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Voir aussi
Show(IWin32Window, String, String)
Affiche un message contenant le texte et la légende spécifiés devant l'objet spécifié.Displays a message box in front of the specified object and with the specified text and caption.
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);
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
Paramètres
- owner
- IWin32Window
Implémentation de IWin32Window auquel appartiendra la boîte de dialogue modale.An implementation of IWin32Window that will own the modal dialog box.
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Remarques
Vous pouvez utiliser le owner
paramètre pour spécifier un objet particulier, qui implémente l' IWin32Window interface, qui servira de fenêtre de niveau supérieur et de propriétaire de la boîte de dialogue.You can use the owner
parameter to specify a particular object, which implements the IWin32Window interface, that will serve as the dialog box's top-level window and owner. Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Par défaut, la boîte de message affiche un bouton OK .By default, the message box displays an OK button.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Show(String, String, MessageBoxButtons)
Affiche un message avec le texte, la légende et les boutons spécifiés.Displays a message box with specified text, caption, and buttons.
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);
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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
Le paramètre buttons
spécifié n'est pas un membre de MessageBoxButtons.The buttons
parameter specified is not a member of MessageBoxButtons.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
Exemples
L’exemple de code suivant montre comment afficher un MessageBox avec les options prises en charge par cette Showsurcharge de.The following code example demonstrates how to display a MessageBox with the options supported by this overload of Show. Après avoir vérifié qu’une variable de chaîne ServerName
,, est vide, l’exemple affiche MessageBoxun, offrant à l’utilisateur la possibilité d’annuler l’opération.After verifying that a string variable, ServerName
, is empty, the example displays a MessageBox, offering the user the option to cancel the operation. Si la Show valeur de retour de la méthode MessageBox est Yeségale à, le formulaire qui affichait est fermé.If the Show method's return value evaluates to Yes, the form that displayed the MessageBox is closed.
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
Remarques
Vous pouvez avoir un maximum de trois boutons sur la boîte de message.You can have a maximum of three buttons on the message box.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Voir aussi
Show(IWin32Window, String)
Affiche un message contenant le texte spécifié devant l'objet spécifié.Displays a message box in front of the specified object and with the specified text.
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);
static member Show : System.Windows.Forms.IWin32Window * string -> System.Windows.Forms.DialogResult
Public Shared Function Show (owner As IWin32Window, text As String) As DialogResult
Paramètres
- owner
- IWin32Window
Implémentation de IWin32Window auquel appartiendra la boîte de dialogue modale.An implementation of IWin32Window that will own the modal dialog box.
- text
- String
Texte à afficher dans le message.The text to display in the message box.
Retours
Une des valeurs de l'objet DialogResult.One of the DialogResult values.
Remarques
Vous pouvez utiliser le owner
paramètre pour spécifier un objet particulier, qui implémente l' IWin32Window interface, qui servira de fenêtre de niveau supérieur et de propriétaire de la boîte de dialogue.You can use the owner
parameter to specify a particular object, which implements the IWin32Window interface, that will serve as the dialog box's top-level window and owner. Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur.
Par défaut, la boîte de message affiche un bouton OK .By default, the message box displays an OK button. La boîte de message ne contient pas de légende dans le titre.The message box does not contain a caption in the title.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Show(String, String)
Affiche un message avec le texte et la légende spécifiés.Displays a message box with specified text and caption.
public:
static System::Windows::Forms::DialogResult Show(System::String ^ text, System::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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
Retours
Une des valeurs de l'objet DialogResult.One of the DialogResult values.
Remarques
Par défaut, la boîte de message affiche un bouton OK .By default, the message box displays an OK button.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Show(String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions)
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut et les options spécifiés.Displays a message box with the specified text, caption, buttons, icon, default button, and options.
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);
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
Paramètres
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
ou-or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
- ou --or-
Le defaultButton
spécifié n'est pas un membre de MessageBoxDefaultButton.The defaultButton
specified is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
ou-or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher un MessageBox avec les options prises en charge par cette Showsurcharge de.The following code example demonstrates how to display a MessageBox with the options supported by this overload of Show. Après avoir vérifié qu’une variable de chaîne ServerName
,, est vide, l’exemple affiche MessageBox une icône avec une zone de question, offrant à l’utilisateur la possibilité d’annuler l’opération.After verifying that a string variable, ServerName
, is empty, the example displays a MessageBox with a question box icon, offering the user the option to cancel the operation. L’exemple utilise le RightAlign membre de l' MessageBoxOptions énumération pour aligner le texte sur le bord droit de la boîte de dialogue.The example uses the RightAlign member of the MessageBoxOptions enumeration to align the text to the right edge of the dialog box. Si la Show valeur de retour de la méthode MessageBox est Yeségale à, le formulaire qui affichait est fermé.If the Show method's return value evaluates to Yes, the form that displayed the MessageBox is closed.
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
Remarques
Vous pouvez avoir un maximum de trois boutons sur la boîte de message.You can have a maximum of three buttons on the message box.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
Voir aussi
Show(IWin32Window, String, String, MessageBoxButtons, MessageBoxIcon, MessageBoxDefaultButton, MessageBoxOptions, String, HelpNavigator, Object)
Affiche un message avec le texte, la légende, les boutons, l'icône, le bouton par défaut, les options et le bouton Aide à l'aide du fichier d'aide spécifié, du HelpNavigator
et de la rubrique d'aide.Displays a message box with the specified text, caption, buttons, icon, default button, options, and Help button, using the specified Help file, HelpNavigator
, and Help topic.
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);
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
Paramètres
- owner
- IWin32Window
Implémentation de IWin32Window auquel appartiendra la boîte de dialogue modale.An implementation of IWin32Window that will own the modal dialog box.
- text
- String
Texte à afficher dans le message.The text to display in the message box.
- caption
- String
Texte à afficher dans la barre de titre du message.The text to display in the title bar of the message box.
- buttons
- MessageBoxButtons
Une des valeurs MessageBoxButtons spécifiant les boutons à afficher dans le message.One of the MessageBoxButtons values that specifies which buttons to display in the message box.
- icon
- MessageBoxIcon
Une des valeurs MessageBoxIcon spécifiant l'icône à afficher dans le message.One of the MessageBoxIcon values that specifies which icon to display in the message box.
- defaultButton
- MessageBoxDefaultButton
Une des valeurs MessageBoxDefaultButton spécifiant le bouton par défaut du message.One of the MessageBoxDefaultButton values that specifies the default button for the message box.
- options
- MessageBoxOptions
Une des valeurs MessageBoxOptions spécifiant les options d'affichage et d'association utilisées dans le message.One of the MessageBoxOptions values that specifies which display and association options will be used for the message box. Vous pouvez passer la valeur 0 si vous souhaitez utiliser les valeurs par défaut.You may pass in 0 if you wish to use the defaults.
- helpFilePath
- String
Chemin d'accès et nom du fichier d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The path and name of the Help file to display when the user clicks the Help button.
- navigator
- HelpNavigator
Une des valeurs de l'objet HelpNavigator.One of the HelpNavigator values.
- param
- Object
ID numérique de la rubrique d'aide à afficher lorsque l'utilisateur clique sur le bouton Aide.The numeric ID of the Help topic to display when the user clicks the Help button.
Retours
Une des valeurs de DialogResult.One of the DialogResult values.
Exceptions
buttons
n’est pas membre de MessageBoxButtonsbuttons
is not a member of MessageBoxButtons.
- ou --or-
icon
n’est pas membre de MessageBoxIconicon
is not a member of MessageBoxIcon.
- ou --or-
Le defaultButton
spécifié n'est pas un membre de MessageBoxDefaultButton.The defaultButton
specified is not a member of MessageBoxDefaultButton.
Une tentative d'affichage du MessageBox a eu lieu dans un processus qui n'est pas exécuté en mode utilisateur interactif.An attempt was made to display the MessageBox in a process that is not running in User Interactive mode. Cela est spécifié par la propriété UserInteractive.This is specified by the UserInteractive property.
options
a spécifié à la fois DefaultDesktopOnly et ServiceNotification.options
specified both DefaultDesktopOnly and ServiceNotification.
ou-or-
buttons
a spécifié une combinaison non valide de MessageBoxButtons.buttons
specified an invalid combination of MessageBoxButtons.
Exemples
L’exemple de code suivant montre comment afficher une boîte de message apparenté à la fenêtre principale.The following code example demonstrates how to show a message box parented to the main window. La boîte de message affiche un bouton aide.The message box displays a Help button. Quand l’utilisateur clique sur le bouton aide Mspaint.chm
, le fichier d’aide s’ouvre et l’onglet Index de l’aide et ovals
la rubrique identifiée par le mot clé sont affichés.When the user clicks the Help button, the Mspaint.chm
Help file is opened and the Help index tab and the topic identified by the ovals
keyword are displayed. L’exemple requiert l’installation Mspaint.chm
du fichier d’aide.The example requires that the Mspaint.chm
Help file is installed.
#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")
Remarques
Une boîte de message est une boîte de dialogue modale, ce qui signifie qu’aucune entrée (clavier ou clic de souris) ne peut se produire à l’exception des objets du formulaire modal.A message box is a modal dialog box, which means no input (keyboard or mouse click) can occur except to objects on the modal form. Le programme doit masquer ou fermer un formulaire modal (en général, en réponse à une action de l’utilisateur) avant qu’une entrée dans un autre formulaire puisse se produire.The program must hide or close a modal form (typically in response to some user action) before input to another form can occur. Vous pouvez utiliser le owner
paramètre pour spécifier un objet particulier, qui implémente l' IWin32Window interface, qui servira de fenêtre de niveau supérieur et de propriétaire de la boîte de dialogue.You can use the owner
parameter to specify a particular object, which implements the IWin32Window interface, that will serve as the dialog box's top-level window and owner.
Quand l’utilisateur clique sur le bouton aide, le fichier d’aide helpFilePath
spécifié dans le paramètre s’ouvre et le contenu d' navigator
aide identifié par le paramètre s’affiche.When the user clicks the Help button, the Help file specified in the helpFilePath
parameter is opened and the Help content identified by the navigator
parameter is displayed. Le formulaire qui possède la boîte de message (ou le formulaire actif) reçoit également HelpRequested l’événement.The form that owns the message box (or the active form) also receives the HelpRequested event.
Les fichiers d’aide compilés fournissent des tables de matières, d’index, de recherche et de mots clés dans les pages.Compiled help files provide table of contents, index, search, and keyword links in pages. Vous pouvez utiliser les valeurs suivantes pour navigator
: TableOfContents, Find, Indexou Topic.You can use the following values for navigator
: TableOfContents, Find, Index, or Topic.
Vous pouvez utiliser param
pour fournir une affination supplémentaire Topic de la commande.You can use param
to provide further refinement of the Topic command. Si la valeur spécifiée dans le navigator
paramètre est TableOfContents, Indexou Find, cette valeur doit être null
.If the value specified in the navigator
parameter is TableOfContents, Index, or Find, this value should be null
. Si le navigator
paramètre fait Topicréférence à, cette valeur doit faire référence à un objet qui contient la valeur numérique de la rubrique à afficher.If the navigator
parameter references Topic, this value should reference an object that contains the numeric value of the topic to display.
Le helpFilePath
paramètre peut être de la forme "c:\path\sample.chm" ou/folder/file.htm.The helpFilePath
parameter can be of the form C:\path\sample.chm or /folder/file.htm.
Sécurité
UIPermission
pour que les sous-fenêtres sécurisées appellent cette méthode.for safe subwindows to call this method. Énumération associée:SafeSubWindowsAssociated enumeration: SafeSubWindows
WebPermission
pour accéder à un fichier d’aide HTML par le biais d’une requête HTTP.to access a HTML help file through a HTTP request. Énumération associée:ConnectAssociated enumeration: Connect
SecurityPermission
pour accéder à un fichier d’aide HTML qui n’est pas pris en charge à partir d’un serveur HTTP.to access a HTML help file not served from a HTTP server. Énumération associée:UnmanagedCodeAssociated enumeration: UnmanagedCode