CommonDialog.ShowDialog メソッド ()
既定のオーナーを使用してコモン ダイアログ ボックスを実行します。
Overloads Public Function ShowDialog() As DialogResult
[C#]
public DialogResult ShowDialog();
[C++]
public: DialogResult ShowDialog();
[JScript]
public function ShowDialog() : DialogResult;
戻り値
ユーザーがダイアログ ボックスの [OK] をクリックした場合は DialogResult.OK 。それ以外の場合は、 DialogResult.Cancel 。
解説
このメソッドは、 RunDialog を実装します。
使用例
[Visual Basic, C#, C++] CommonDialog の ColorDialog 実装を使用し、ダイアログ ボックスを作成して表示する例を次に示します。この例では、 TextBox と Button が配置されている既存のフォームからメソッドが呼び出されることを前提としています。
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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET
.NET Framework セキュリティ:
- PrintingPermission (PrintDialog から印刷するために必要なアクセス許可) PrintingPermissionLevel.SafePrinting (関連する列挙体)
- UIPermission (セーフ サブウィンドウでこのメソッドを呼び出すために必要なアクセス許可) UIPermissionWindow.SafeSubWindows (関連する列挙体)
参照
CommonDialog クラス | CommonDialog メンバ | System.Windows.Forms 名前空間 | CommonDialog.ShowDialog オーバーロードの一覧 | RunDialog | DialogResult