CommonDialog.ShowDialog Metoda
Definicja
Uruchamia wspólne okno dialogowe.Runs a common dialog box.
Przeciążenia
ShowDialog() |
Uruchamia wspólne okno dialogowe z domyślnym właścicielem.Runs a common dialog box with a default owner. |
ShowDialog(IWin32Window) |
Uruchamia wspólne okno dialogowe z określonym właścicielem.Runs a common dialog box with the specified owner. |
ShowDialog()
Uruchamia wspólne okno dialogowe z domyślnym właścicielem.Runs a common dialog box with a default owner.
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
Zwraca
OKJeśli użytkownik kliknie przycisk OK w oknie dialogowym; w przeciwnym razie Cancel .OK if the user clicks OK in the dialog box; otherwise, Cancel.
Przykłady
Poniższy przykład kodu używa ColorDialog implementacji CommonDialog i ilustruje tworzenie i wyświetlanie okna dialogowego.The following code example uses the ColorDialog implementation of CommonDialog and illustrates creating and showing a dialog box. Ten przykład wymaga, aby metoda została wywołana z poziomu istniejącego formularza, który ma TextBox i Button umieszczony w nim.This example requires that the method is called from within an existing form, which has a TextBox and Button placed on it.
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
Uwagi
Ta metoda implementuje RunDialog .This method implements RunDialog.
Zobacz też
Dotyczy
ShowDialog(IWin32Window)
Uruchamia wspólne okno dialogowe z określonym właścicielem.Runs a common dialog box with the specified 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
Parametry
- owner
- IWin32Window
Każdy obiekt, który implementuje IWin32Window , reprezentujący okno najwyższego poziomu, które będzie miało własne okno dialogowe.Any object that implements IWin32Window that represents the top-level window that will own the modal dialog box.
Zwraca
OKJeśli użytkownik kliknie przycisk OK w oknie dialogowym; w przeciwnym razie Cancel .OK if the user clicks OK in the dialog box; otherwise, Cancel.
Uwagi
Ta wersja ShowDialog metody umożliwia określenie konkretnego formularza lub kontrolki, które będą mieć odpowiednie okno dialogowe, które jest wyświetlane.This version of the ShowDialog method allows you to specify a specific form or control that will own the dialog box that is shown. Jeśli używasz wersji tej metody, która nie ma parametrów, wyświetlane okno dialogowe będzie własnością automatycznie przez aktualnie aktywne okno aplikacji.If you use the version of this method that has no parameters, the dialog box being shown would be owned automatically by the currently active window of your application.