CommonDialog.ShowDialog 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
运行通用对话框。
重载
ShowDialog() |
用默认的所有者运行通用对话框。 |
ShowDialog(IWin32Window) |
运行具有指定所有者的通用对话框。 |
ShowDialog()
- Source:
- CommonDialog.cs
- Source:
- CommonDialog.cs
- Source:
- CommonDialog.cs
用默认的所有者运行通用对话框。
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
返回
如果用户在对话框中单击“确定”,则为 OK;否则为 Cancel。
示例
下面的代码示例使用 的ColorDialogCommonDialog实现,并说明了如何创建和显示对话框。 此示例要求从现有窗体中调用 方法,该窗体具有 TextBox 并 Button 放置在该窗体上。
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
注解
此方法实现 RunDialog。
另请参阅
适用于
ShowDialog(IWin32Window)
- Source:
- CommonDialog.cs
- Source:
- CommonDialog.cs
- Source:
- CommonDialog.cs
运行具有指定所有者的通用对话框。
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
参数
- owner
- IWin32Window
任何实现 IWin32Window(表示将拥有模式对话框的顶级窗口)的对象。
返回
如果用户在对话框中单击“确定”,则为 OK;否则为 Cancel。
注解
此版本的 ShowDialog 方法允许您指定将拥有所显示对话框的特定窗体或控件。 如果使用没有参数的此方法版本,则应用程序的当前活动窗口将自动拥有显示的对话框。