Font 构造函数

定义

初始化新 Font,它使用指定的现有 FontFontStyle

重载

Font(Font, FontStyle)

初始化新 Font,它使用指定的现有 FontFontStyle 枚举。

Font(String, Single, FontStyle, GraphicsUnit, Byte, Boolean)

使用指定的大小、样式、单位和字符集初始化新 Font

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean)

使用指定的大小、样式、单位和字符集初始化新的 Font

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte)

使用指定的大小、样式、单位和字符集初始化新的 Font

Font(String, Single, FontStyle, GraphicsUnit)

使用指定的大小、样式和单位初始化新的 Font

Font(FontFamily, Single, FontStyle, GraphicsUnit)

使用指定的大小、样式和单位初始化新的 Font

Font(String, Single, FontStyle, GraphicsUnit, Byte)

使用指定的大小、样式、单位和字符集初始化新的 Font

Font(String, Single, FontStyle)

使用指定的大小和样式初始化新 Font

Font(FontFamily, Single, GraphicsUnit)

使用指定的大小和单位初始化新的 Font。 将此样式设置为 Regular

Font(FontFamily, Single, FontStyle)

使用指定的大小和样式初始化新 Font

Font(String, Single)

使用指定的大小初始化新 Font

Font(FontFamily, Single)

使用指定的大小初始化新 Font

Font(String, Single, GraphicsUnit)

使用指定的大小和单位初始化新的 Font。 样式设置为 Regular

Font(Font, FontStyle)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

初始化新 Font,它使用指定的现有 FontFontStyle 枚举。

public:
 Font(System::Drawing::Font ^ prototype, System::Drawing::FontStyle newStyle);
public Font (System.Drawing.Font prototype, System.Drawing.FontStyle newStyle);
new System.Drawing.Font : System.Drawing.Font * System.Drawing.FontStyle -> System.Drawing.Font
Public Sub New (prototype As Font, newStyle As FontStyle)

参数

prototype
Font

从中创建新 Font 的现有 Font

newStyle
FontStyle

应用于新 FontFontStyle。 可以用 OR 运算符将 FontStyle 枚举的多个值组合起来。

示例

下面的代码示例演示 Inequality 运算符、 Font 构造函数和 Bold 属性。 此示例旨在与包含名为 的 Button2按钮的 Windows 窗体一起使用。 将以下代码粘贴到窗体中,并将 Button2_Click 方法与按钮的 Click 事件相关联。

void Button2_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   if ( this->BackColor != SystemColors::ControlDark )
   {
      this->BackColor = SystemColors::ControlDark;
   }

   if (  !(this->Font->Bold) )
   {
      this->Font = gcnew System::Drawing::Font( this->Font,FontStyle::Bold );
   }
}
private void Button2_Click(System.Object sender, System.EventArgs e)
{

    if (this.BackColor != SystemColors.ControlDark)
    {
        this.BackColor = SystemColors.ControlDark;
    }
    if (!(this.Font.Bold))
    {
        this.Font = new Font(this.Font, FontStyle.Bold);
    }
}
Private Sub Button2_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button2.Click

    If (Color.op_Inequality(Me.BackColor, SystemColors.ControlDark)) Then
        Me.BackColor = SystemColors.ControlDark
    End If
    If Not (Me.Font.Bold) Then
        Me.Font = New Font(Me.Font, FontStyle.Bold)
    End If
End Sub

注解

对于基于 .NET Framework 2.0 及更早版本的本地化应用程序,当用于生成应用程序的计算机上尚未安装该字体时,指定prototype字体将导致改用 Microsoft Sans Serif 字体。 如果应用程序依赖于此行为,并且必须针对 .NET Framework 3.0 重新编译应用程序,则应为 prototype指定 Microsoft Sans Serif 字体。

适用于

Font(String, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小、样式、单位和字符集初始化新 Font

public:
 Font(System::String ^ familyName, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit, System::Byte gdiCharSet, bool gdiVerticalFont);
public Font (string familyName, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont);
new System.Drawing.Font : string * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit * byte * bool -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single, style As FontStyle, unit As GraphicsUnit, gdiCharSet As Byte, gdiVerticalFont As Boolean)

参数

familyName
String

FontFontFamily 的字符串表示形式。

emSize
Single

新字体的全身大小(采用 unit 参数指定的单位)。

style
FontStyle

新字体的 FontStyle

unit
GraphicsUnit

新字体的 GraphicsUnit

gdiCharSet
Byte

一个 , Byte 它指定要用于此字体的 GDI 字符集。

gdiVerticalFont
Boolean

一个布尔值,指示新 Font 是否派生自 GDI 垂直字体。

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

注解

参数gdiCharSet从 Windows SDK 头文件 WinGDI.h 中定义的列表中获取值。 familyName如果 参数指定的字体未安装在运行应用程序的计算机上或不受支持,则将替换 Microsoft Sans Serif。

另请参阅

适用于

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小、样式、单位和字符集初始化新的 Font

public:
 Font(System::Drawing::FontFamily ^ family, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit, System::Byte gdiCharSet, bool gdiVerticalFont);
public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont);
new System.Drawing.Font : System.Drawing.FontFamily * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit * byte * bool -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single, style As FontStyle, unit As GraphicsUnit, gdiCharSet As Byte, gdiVerticalFont As Boolean)

参数

family
FontFamily

FontFontFamily

emSize
Single

新字体的全身大小(采用 unit 参数指定的单位)。

style
FontStyle

新字体的 FontStyle

unit
GraphicsUnit

新字体的 GraphicsUnit

gdiCharSet
Byte

一个 Byte,它指定

要用于此字体的 GDI 字符集。

gdiVerticalFont
Boolean

一个布尔值,指示新字体是否派生自 GDI 垂直字体。

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

familynull

注解

参数gdiCharSet从 Windows SDK 头文件 WinGDI.h 中定义的列表中获取值。

适用于

Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小、样式、单位和字符集初始化新的 Font

public:
 Font(System::Drawing::FontFamily ^ family, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit, System::Byte gdiCharSet);
public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet);
new System.Drawing.Font : System.Drawing.FontFamily * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit * byte -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single, style As FontStyle, unit As GraphicsUnit, gdiCharSet As Byte)

参数

family
FontFamily

FontFontFamily

emSize
Single

新字体的全身大小(采用 unit 参数指定的单位)。

style
FontStyle

新字体的 FontStyle

unit
GraphicsUnit

新字体的 GraphicsUnit

gdiCharSet
Byte

一个 Byte,它指定

要用于新字体的 GDI 字符集。

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

familynull

注解

参数gdiCharSet从 Windows SDK 头文件 WinGDI.h 中定义的列表中获取值。

适用于

Font(String, Single, FontStyle, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小、样式和单位初始化新的 Font

public:
 Font(System::String ^ familyName, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit);
public Font (string familyName, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit);
new System.Drawing.Font : string * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single, style As FontStyle, unit As GraphicsUnit)

参数

familyName
String

FontFontFamily 的字符串表示形式。

emSize
Single

新字体的全身大小(采用 unit 参数指定的单位)。

style
FontStyle

新字体的 FontStyle

unit
GraphicsUnit

新字体的 GraphicsUnit

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

示例

下面的代码示例演示如何使用 Font 构造函数。 此示例旨在与 Windows 窗体 一起使用。 若要运行此示例,请将此代码粘贴到包含名为 的Button2按钮的窗体中,并将 方法与Click按钮的 事件相关联Button2_Click


private:
    void Button2_Click(System::Object^ sender,
        System::EventArgs^ e)
    {
        Button2->Font = gcnew System::Drawing::Font
            (FontFamily::GenericMonospace, 12.0F,
            FontStyle::Italic, GraphicsUnit::Pixel);
    }

private void Button2_Click(System.Object sender, System.EventArgs e)
{

    Button2.Font = new Font(FontFamily.GenericMonospace, 12.0F, 
        FontStyle.Italic, GraphicsUnit.Pixel);
}

Private Sub Button2_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button2.Click

    Button2.Font = New Font(FontFamily.GenericMonospace, 12.0F, _
        FontStyle.Italic, GraphicsUnit.Pixel)

End Sub

注解

Windows 窗体应用程序支持 TrueType 字体,并且对 OpenType 字体的支持有限。 familyName如果 参数指定的字体未安装在运行应用程序的计算机上或不受支持,则将替换 Microsoft Sans Serif。

适用于

Font(FontFamily, Single, FontStyle, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小、样式和单位初始化新的 Font

public:
 Font(System::Drawing::FontFamily ^ family, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit);
public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit);
new System.Drawing.Font : System.Drawing.FontFamily * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single, style As FontStyle, unit As GraphicsUnit)

参数

family
FontFamily

FontFontFamily

emSize
Single

新字体的全身大小(采用 unit 参数指定的单位)。

style
FontStyle

新字体的 FontStyle

unit
GraphicsUnit

新字体的 GraphicsUnit

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

familynull

适用于

Font(String, Single, FontStyle, GraphicsUnit, Byte)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小、样式、单位和字符集初始化新的 Font

public:
 Font(System::String ^ familyName, float emSize, System::Drawing::FontStyle style, System::Drawing::GraphicsUnit unit, System::Byte gdiCharSet);
public Font (string familyName, float emSize, System.Drawing.FontStyle style, System.Drawing.GraphicsUnit unit, byte gdiCharSet);
new System.Drawing.Font : string * single * System.Drawing.FontStyle * System.Drawing.GraphicsUnit * byte -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single, style As FontStyle, unit As GraphicsUnit, gdiCharSet As Byte)

参数

familyName
String

FontFontFamily 的字符串表示形式。

emSize
Single

新字体的全身大小(采用 unit 参数指定的单位)。

style
FontStyle

新字体的 FontStyle

unit
GraphicsUnit

新字体的 GraphicsUnit

gdiCharSet
Byte

一个 , Byte 它指定要用于此字体的 GDI 字符集。

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

注解

参数gdiCharSet从 Windows SDK 头文件 WinGDI.h 中定义的列表中获取值。 Windows 窗体应用程序支持 TrueType 字体,并且对 OpenType 字体的支持有限。 familyName如果 参数指定的字体未安装在运行应用程序的计算机上或不受支持,则将替换 Microsoft Sans Serif。

另请参阅

适用于

Font(String, Single, FontStyle)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小和样式初始化新 Font

public:
 Font(System::String ^ familyName, float emSize, System::Drawing::FontStyle style);
public Font (string familyName, float emSize, System.Drawing.FontStyle style);
new System.Drawing.Font : string * single * System.Drawing.FontStyle -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single, style As FontStyle)

参数

familyName
String

FontFontFamily 的字符串表示形式。

emSize
Single

新字体的全身大小(以磅为单位)。

style
FontStyle

新字体的 FontStyle

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

注解

生成的字体的 Unit 属性设置为 Point。 Windows 窗体应用程序支持 TrueType 字体,并且对 OpenType 字体的支持有限。 familyName如果 参数指定的字体未安装在运行应用程序的计算机上或不受支持,则将替换 Microsoft Sans Serif。

适用于

Font(FontFamily, Single, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小和单位初始化新的 Font。 将此样式设置为 Regular

public:
 Font(System::Drawing::FontFamily ^ family, float emSize, System::Drawing::GraphicsUnit unit);
public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.GraphicsUnit unit);
new System.Drawing.Font : System.Drawing.FontFamily * single * System.Drawing.GraphicsUnit -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single, unit As GraphicsUnit)

参数

family
FontFamily

FontFontFamily

emSize
Single

新字体的全身大小(采用 unit 参数指定的单位)。

unit
GraphicsUnit

新字体的 GraphicsUnit

例外

familynull

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

注解

生成的字体的 Style 属性设置为 FontStyle.Regular

适用于

Font(FontFamily, Single, FontStyle)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小和样式初始化新 Font

public:
 Font(System::Drawing::FontFamily ^ family, float emSize, System::Drawing::FontStyle style);
public Font (System.Drawing.FontFamily family, float emSize, System.Drawing.FontStyle style);
new System.Drawing.Font : System.Drawing.FontFamily * single * System.Drawing.FontStyle -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single, style As FontStyle)

参数

family
FontFamily

FontFontFamily

emSize
Single

新字体的全身大小(以磅为单位)。

style
FontStyle

新字体的 FontStyle

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

familynull

示例

下面的代码示例演示如何将按钮的 属性设置为 Font 新的粗体样式 Font。 此示例旨在与包含名为 Button1的按钮的 Windows 窗体一起使用。 将以下代码粘贴到窗体中,并将 Button1_Click 方法与按钮的事件 Click 相关联。

private:
   void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      Button1->Font = gcnew System::Drawing::Font( FontFamily::GenericSansSerif,12.0F,FontStyle::Bold );
   }
private void Button1_Click(System.Object sender, System.EventArgs e)
{
    if (Button1.Font.Style != FontStyle.Bold)
            Button1.Font = new Font(FontFamily.GenericSansSerif,
            12.0F, FontStyle.Bold);
}
 Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    If Not Button1.Font.Style = FontStyle.Bold Then
        Button1.Font = New Font(FontFamily.GenericSansSerif, _
            12.0F, FontStyle.Bold)
    End If
End Sub

注解

生成的字体的 Unit 属性设置为 Point

适用于

Font(String, Single)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小初始化新 Font

public:
 Font(System::String ^ familyName, float emSize);
public Font (string familyName, float emSize);
new System.Drawing.Font : string * single -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single)

参数

familyName
String

FontFontFamily 的字符串表示形式。

emSize
Single

新字体的全身大小(以磅为单位)。

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

示例

下面的代码示例演示如何使用 Font 构造函数。 此示例设计为与 Windows 窗体一起使用,需要 一个 PaintEventArgse,它是 事件的一个参数 Paint

private void ConstructFontWithString(PaintEventArgs e)
{
    Font font1 = new Font("Arial", 20);
    e.Graphics.DrawString("Arial Font", font1, Brushes.Red, new PointF(10, 10));
}
Private Sub ConstructFontWithString(ByVal e As PaintEventArgs)
    Dim font1 As New Font("Arial", 20)
    e.Graphics.DrawString("Arial Font", font1, Brushes.Red, New PointF(10, 10))
End Sub

注解

生成的字体的 Style 属性设置为 FontStyle.Regular ,属性 Unit 设置为 GraphicsUnit.Point。 Windows 窗体应用程序支持 TrueType 字体,并且对 OpenType 字体的支持有限。 familyName如果 参数指定的字体未安装在运行应用程序的计算机上或不受支持,则将替换 Microsoft Sans Serif。

适用于

Font(FontFamily, Single)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小初始化新 Font

public:
 Font(System::Drawing::FontFamily ^ family, float emSize);
public Font (System.Drawing.FontFamily family, float emSize);
new System.Drawing.Font : System.Drawing.FontFamily * single -> System.Drawing.Font
Public Sub New (family As FontFamily, emSize As Single)

参数

family
FontFamily

FontFontFamily

emSize
Single

新字体的全身大小(以磅为单位)。

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

注解

生成的字体的 Style 属性设置为 Regular ,属性 Unit 设置为 Point

适用于

Font(String, Single, GraphicsUnit)

Source:
Font.cs
Source:
Font.cs
Source:
Font.cs

使用指定的大小和单位初始化新的 Font。 样式设置为 Regular

public:
 Font(System::String ^ familyName, float emSize, System::Drawing::GraphicsUnit unit);
public Font (string familyName, float emSize, System.Drawing.GraphicsUnit unit);
new System.Drawing.Font : string * single * System.Drawing.GraphicsUnit -> System.Drawing.Font
Public Sub New (familyName As String, emSize As Single, unit As GraphicsUnit)

参数

familyName
String

FontFontFamily 的字符串表示形式。

emSize
Single

新字体的全身大小(采用 unit 参数指定的单位)。

unit
GraphicsUnit

新字体的 GraphicsUnit

例外

emSize 小于或等于 0、计算结果为无限大或者不是有效数字。

注解

生成的字体的 Style 属性设置为 FontStyle.Regular

适用于