CommonDialog.ShowDialog Méthode

Définition

Exécute une boîte de dialogue commune.

Surcharges

ShowDialog()

Exécute une boîte de dialogue commune avec un propriétaire par défaut.

ShowDialog(IWin32Window)

Exécute une boîte de dialogue commune avec le propriétaire spécifié.

ShowDialog()

Exécute une boîte de dialogue commune avec un propriétaire par défaut.

public:
 System::Windows::Forms::DialogResult ShowDialog();
public System.Windows.Forms.DialogResult ShowDialog ();
member this.ShowDialog : unit -> System.Windows.Forms.DialogResult
Public Function ShowDialog () As DialogResult

Retours

OK si l'utilisateur clique sur OK dans la boîte de dialogue ; sinon, Cancel.

Exemples

L’exemple de code suivant utilise l’implémentation ColorDialog de CommonDialog et illustre la création et l’affichage d’une boîte de dialogue. Cet exemple exige que la méthode soit appelée à partir d’un formulaire existant, qui a un TextBox et Button placé dessus.

private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      ColorDialog^ MyDialog = gcnew ColorDialog;
      // Keeps the user from selecting a custom color.
      MyDialog->AllowFullOpen = false;
      // Allows the user to get help. (The default is false.)
      MyDialog->ShowHelp = true;
      // Sets the initial color select to the current text color.
      MyDialog->Color = textBox1->ForeColor;
      
      // Update the text box color if the user clicks OK 
      if ( MyDialog->ShowDialog() == ::System::Windows::Forms::DialogResult::OK )
      {
         textBox1->ForeColor = MyDialog->Color;
      }
   }
private void button1_Click(object sender, System.EventArgs e)
 {
    ColorDialog MyDialog = new ColorDialog();
    // Keeps the user from selecting a custom color.
    MyDialog.AllowFullOpen = false ;
    // Allows the user to get help. (The default is false.)
    MyDialog.ShowHelp = true ;
    // Sets the initial color select to the current text color.
    MyDialog.Color = textBox1.ForeColor ;
    
    // Update the text box color if the user clicks OK 
    if (MyDialog.ShowDialog() == DialogResult.OK)
        textBox1.ForeColor =  MyDialog.Color;
 }
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim MyDialog As New ColorDialog()
    ' Keeps the user from selecting a custom color.
    MyDialog.AllowFullOpen = False
    ' Allows the user to get help. (The default is false.)
    MyDialog.ShowHelp = True
    ' Sets the initial color select to the current text color,
    MyDialog.Color = TextBox1.ForeColor

    ' Update the text box color if the user clicks OK 
    If (MyDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
        TextBox1.ForeColor = MyDialog.Color
    End If
End Sub

Remarques

Cette méthode implémente RunDialog.

Voir aussi

S’applique à

ShowDialog(IWin32Window)

Exécute une boîte de dialogue commune avec le propriétaire spécifié.

public:
 System::Windows::Forms::DialogResult ShowDialog(System::Windows::Forms::IWin32Window ^ owner);
public System.Windows.Forms.DialogResult ShowDialog (System.Windows.Forms.IWin32Window owner);
public System.Windows.Forms.DialogResult ShowDialog (System.Windows.Forms.IWin32Window? owner);
member this.ShowDialog : System.Windows.Forms.IWin32Window -> System.Windows.Forms.DialogResult
Public Function ShowDialog (owner As IWin32Window) As DialogResult

Paramètres

owner
IWin32Window

Tout objet qui implémente IWin32Window et représente la fenêtre de niveau supérieur à laquelle va appartenir la boîte de dialogue modale.

Retours

OK si l’utilisateur clique sur OK dans la boîte de dialogue ; sinon, Cancel.

Remarques

Cette version de la ShowDialog méthode vous permet de spécifier un formulaire ou un contrôle spécifique qui sera propriétaire de la boîte de dialogue qui s’affiche. Si vous utilisez la version de cette méthode qui n’a aucun paramètre, la boîte de dialogue affichée appartient automatiquement à la fenêtre actuellement active de votre application.

S’applique à