CommonDialog 类
定义
命名空间:
System.Windows.Forms
程序集:System.Windows.Forms.dll
Source:CommonDialog.cs
Source:CommonDialog.cs
Source:CommonDialog.cs
Source:CommonDialog.cs
Source:CommonDialog.cs
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定用于在屏幕上显示对话框的基类。
public ref class CommonDialog abstract : System::ComponentModel::Component
public abstract class CommonDialog : System.ComponentModel.Component
type CommonDialog = class
inherit Component
Public MustInherit Class CommonDialog
Inherits Component
继承
Object
MarshalByRefObject
Component
CommonDialog
派生
System.Windows.Forms.ColorDialog
System.Windows.Forms.FileDialog
System.Windows.Forms.FolderBrowserDialog
System.Windows.Forms.FontDialog
System.Windows.Forms.PageSetupDialog
System.Windows.Forms.PrintDialog
更多…
示例
下面的代码示例使用 ColorDialog 实现 CommonDialog 并演示如何创建和显示对话框。 此示例要求从现有窗体中调用该方法,该窗体中具有一个 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() = DialogResult.OK) Then
TextBox1.ForeColor = MyDialog.Color
End If
End Sub
注解
通过调用RunDialog以创建特定的通用对话框来实现ShowDialog继承的类。 继承的类可以选择替代 HookProc 来实现特定的对话框挂钩功能。
构造函数
名称
说明
CommonDialog()
初始化 CommonDialog 类的新实例。
属性
名称
说明
CanRaiseEvents
获取一个值,该值指示组件是否可以引发事件。
(继承自 Component)
Container
IContainer获取包含 .Component
(继承自 Component)
DesignMode
获取一个值,该值指示当前是否 Component 处于设计模式。
(继承自 Component)
Events
获取附加到此 Component对象的事件处理程序的列表。
(继承自 Component)
Site
获取或设置 ISite 的 Component。
(继承自 Component)
Tag
获取或设置一个对象,该对象包含有关控件的数据。
方法
名称
说明
CreateObjRef(Type)
创建一个对象,其中包含生成用于与远程对象通信的代理所需的所有相关信息。
(继承自 MarshalByRefObject)
Dispose()
释放该 Component命令使用的所有资源。
(继承自 Component)
Dispose(Boolean)
释放由托管资源使用 Component 的非托管资源,并选择性地释放托管资源。
(继承自 Component)
Equals(Object)
确定指定的对象是否等于当前对象。
(继承自 Object)
GetHashCode()
用作默认哈希函数。
(继承自 Object)
GetLifetimeService()
已过时.
检索控制此实例的生存期策略的当前生存期服务对象。
(继承自 MarshalByRefObject)
GetService(Type)
返回一个对象,该对象表示服务由 Component 或其 Container提供的服务。
(继承自 Component)
GetType()
获取当前实例的 Type。
(继承自 Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)
定义重写的通用对话框挂钩过程,以便向通用对话框添加特定功能。
InitializeLifetimeService()
已过时.
获取生存期服务对象来控制此实例的生存期策略。
(继承自 MarshalByRefObject)
MemberwiseClone()
创建当前 Object的浅表副本。
(继承自 Object)
MemberwiseClone(Boolean)
创建当前 MarshalByRefObject 对象的浅表副本。
(继承自 MarshalByRefObject)
OnHelpRequest(EventArgs)
引发 HelpRequest 事件。
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)
定义重写的所有者窗口过程,以向通用对话框添加特定功能。
Reset()
在派生类中重写时,将通用对话框的属性重置为其默认值。
RunDialog(IntPtr)
在派生类中重写时,指定一个通用对话框。
ShowDialog()
运行具有默认所有者的通用对话框。
ShowDialog(IWin32Window)
运行具有指定所有者的公用对话框。
ToString()
返回包含 String 的名称 Component(如果有)。 不应重写此方法。
(继承自 Component)
活动
名称
说明
Disposed
当组件通过对方法的调用 Dispose() 释放时发生。
(继承自 Component)
HelpRequest
当用户单击常见对话框中的“帮助”按钮时发生。
适用于