FontDialog 类

定义

提示用户从本地计算机上安装的字体中选择一种字体。Prompts the user to choose a font from among those installed on the local computer.

public ref class FontDialog : System::Windows::Forms::CommonDialog
public class FontDialog : System.Windows.Forms.CommonDialog
type FontDialog = class
    inherit CommonDialog
Public Class FontDialog
Inherits CommonDialog
继承

示例

下面的代码示例使用ShowDialogFontDialog显示。The following code example uses ShowDialog to display a FontDialog. 此代码要求Form已创建TextBox , 并在其上放置了一个按钮。This code requires that a Form has already been created with a TextBox and button placed on it. 它还要求fontDialog1已创建。It also requires that the fontDialog1 has been created. Font包含大小信息, 但不包含颜色信息。The Font contains the size information but not the color information.

private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      fontDialog1->ShowColor = true;

      fontDialog1->Font = textBox1->Font;
      fontDialog1->Color = textBox1->ForeColor;

      if ( fontDialog1->ShowDialog() != ::DialogResult::Cancel )
      {
         textBox1->Font = fontDialog1->Font;
         textBox1->ForeColor = fontDialog1->Color;
      }
   }
private void button1_Click(object sender, System.EventArgs e)
 {
    fontDialog1.ShowColor = true;

    fontDialog1.Font = textBox1.Font;
    fontDialog1.Color = textBox1.ForeColor;

    if(fontDialog1.ShowDialog() != DialogResult.Cancel )
    {
       textBox1.Font = fontDialog1.Font ;
       textBox1.ForeColor = fontDialog1.Color;
    }
 }
 
Private Sub button1_Click(sender As Object, e As System.EventArgs)
    fontDialog1.ShowColor = True

    fontDialog1.Font = textBox1.Font
    fontDialog1.Color = textBox1.ForeColor

    If fontDialog1.ShowDialog() <> DialogResult.Cancel Then
        textBox1.Font = fontDialog1.Font
        textBox1.ForeColor = fontDialog1.Color
    End If
End Sub

注解

必须调用继承ShowDialog的成员才能创建此特定的公共对话框。The inherited member ShowDialog must be invoked to create this specific common dialog box. HookProc可以重写以实现特定的对话框挂钩功能。HookProc can be overridden to implement specific dialog box hook functionality.

创建的实例FontDialog时, 某些读/写属性被设置为初始值。When you create an instance of FontDialog, some of the read/write properties are set to initial values. 有关这些值的列表, 请参见FontDialog构造函数。For a list of these values, see the FontDialog constructor.

构造函数

FontDialog()

初始化 FontDialog 类的新实例。Initializes a new instance of the FontDialog class.

字段

EventApply

具有 Apply 事件。Owns the Apply event.

属性

AllowScriptChange

获取或设置一个值,该值指示用户能否更改“脚本”组合框中指定的字符集,以显示除了当前所显示字符集以外的字符集。Gets or sets a value indicating whether the user can change the character set specified in the Script combo box to display a character set other than the one currently displayed.

AllowSimulations

获取或设置一个值,该值指示对话框是否允许图形设备接口 (GDI) 字体模拟。Gets or sets a value indicating whether the dialog box allows graphics device interface (GDI) font simulations.

AllowVectorFonts

获取或设置一个值,该值指示对话框是否允许选择矢量字体。Gets or sets a value indicating whether the dialog box allows vector font selections.

AllowVerticalFonts

获取或设置一个值,该值指示对话框是既显示垂直字体又显示水平字体,还是只显示水平字体。Gets or sets a value indicating whether the dialog box displays both vertical and horizontal fonts or only horizontal fonts.

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
Color

获取或设置选定字体的颜色。Gets or sets the selected font color.

Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(继承自 Component)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 Component)
FixedPitchOnly

获取或设置一个值,该值指示对话框是否只允许选择固定间距字体。Gets or sets a value indicating whether the dialog box allows only the selection of fixed-pitch fonts.

Font

获取或设置选定的字体。Gets or sets the selected font.

FontMustExist

获取或设置一个值,该值指示对话框是否指定当用户尝试选择不存在的字体或样式时的错误条件。Gets or sets a value indicating whether the dialog box specifies an error condition if the user attempts to select a font or style that does not exist.

MaxSize

获取或设置用户可选择的最大磅值。Gets or sets the maximum point size a user can select.

MinSize

获取或设置用户可选择的最小磅值。Gets or sets the minimum point size a user can select.

Options

获取用来初始化 FontDialog 的值。Gets values to initialize the FontDialog.

ScriptsOnly

获取或设置一个值,该值指示对话框是否允许为所有非 OEM 和 Symbol 字符集以及 ANSI 字符集选择字体。Gets or sets a value indicating whether the dialog box allows selection of fonts for all non-OEM and Symbol character sets, as well as the ANSI character set.

ShowApply

获取或设置一个值,该值指示对话框是否包含“应用”按钮。Gets or sets a value indicating whether the dialog box contains an Apply button.

ShowColor

获取或设置一个值,该值指示对话框是否显示颜色选择。Gets or sets a value indicating whether the dialog box displays the color choice.

ShowEffects

获取或设置一个值,该值指示对话框是否包含允许用户指定删除线、下划线和文本颜色选项的控件。Gets or sets a value indicating whether the dialog box contains controls that allow the user to specify strikethrough, underline, and text color options.

ShowHelp

获取或设置一个值,该值指示对话框是否显示“帮助”按钮。Gets or sets a value indicating whether the dialog box displays a Help button.

Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(继承自 Component)
Tag

获取或设置一个对象,该对象包含控件的数据。Gets or sets an object that contains data about the control.

(继承自 CommonDialog)

方法

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(继承自 Component)
Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(继承自 Component)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
HookProc(IntPtr, Int32, IntPtr, IntPtr)

指定为将特定功能添加到通用对话框而重写的通用对话框挂钩程序。Specifies the common dialog box hook procedure that is overridden to add specific functionality to a common dialog box.

InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 MarshalByRefObject)
OnApply(EventArgs)

引发 Apply 事件。Raises the Apply event.

OnHelpRequest(EventArgs)

引发 HelpRequest 事件。Raises the HelpRequest event.

(继承自 CommonDialog)
OwnerWndProc(IntPtr, Int32, IntPtr, IntPtr)

定义要重写的所有者窗口过程,以便向通用对话框添加特定功能。Defines the owner window procedure that is overridden to add specific functionality to a common dialog box.

(继承自 CommonDialog)
Reset()

将所有对话框选项重置为默认值。Resets all dialog box options to their default values.

RunDialog(IntPtr)

指定文件对话框。Specifies a file dialog box.

ShowDialog()

用默认的所有者运行通用对话框。Runs a common dialog box with a default owner.

(继承自 CommonDialog)
ShowDialog(IWin32Window)

运行具有指定所有者的通用对话框。Runs a common dialog box with the specified owner.

(继承自 CommonDialog)
ToString()

检索包含对话框中当前选定字体的名称的字符串。Retrieves a string that includes the name of the current font selected in the dialog box.

事件

Apply

当用户单击字体对话框中的“应用”按钮时发生。Occurs when the user clicks the Apply button in the font dialog box.

Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)
HelpRequest

当用户单击通用对话框中的“帮助”按钮时发生。Occurs when the user clicks the Help button on a common dialog box.

(继承自 CommonDialog)

适用于

另请参阅