次の方法で共有


CommonDialog.ShowDialog メソッド

コモン ダイアログ ボックスを実行します。

オーバーロードの一覧

既定のオーナーを使用してコモン ダイアログ ボックスを実行します。

.NET Compact Framework でもサポート。

[Visual Basic] Overloads Public Function ShowDialog() As DialogResult

[C#] public DialogResult ShowDialog();

[C++] public: DialogResult ShowDialog();

[JScript] public function ShowDialog() : DialogResult;

指定したオーナーを使用してコモン ダイアログ ボックスを実行します。

[Visual Basic] Overloads Public Function ShowDialog(IWin32Window) As DialogResult

[C#] public DialogResult ShowDialog(IWin32Window);

[C++] public: DialogResult ShowDialog(IWin32Window*);

[JScript] public function ShowDialog(IWin32Window) : DialogResult;

使用例

[Visual Basic, C#, C++] CommonDialogColorDialog 実装を使用し、ダイアログ ボックスを作成して表示する例を次に示します。この例では、 TextBoxButton が配置されている既存のフォームからメソッドが呼び出されることを前提としています。

[Visual Basic, C#, C++] メモ   ここでは、ShowDialog のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Protected Sub button1_Click(sender As Object, e As System.EventArgs)
    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() = DialogResult.OK) Then
        textBox1.ForeColor =  MyDialog.Color
    End If

End Sub 'button1_Click

[C#] 
protected 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;
 }
    

[C++] 
protected:
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;
 }
    

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

CommonDialog クラス | CommonDialog メンバ | System.Windows.Forms 名前空間