Font 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
| 名稱 | Description |
|---|---|
| Font(Font, FontStyle) | |
| 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(FontFamily, Single, FontStyle) |
使用指定的大小與樣式初始化新檔案 Font 。 |
| Font(String, Single) |
使用指定大小初始化新資料 Font 。 |
| Font(FontFamily, Single) |
使用指定大小初始化新資料 Font 。 |
| Font(String, Single, GraphicsUnit) |
Font(Font, FontStyle)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
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)
參數
範例
以下程式碼範例展示了 Inequality 運算子、 Font 建構子及性質 Bold 。 此範例設計用於包含名為 Button2的按鈕的 Windows 表單。 將以下程式碼貼到表單中,並將方法與按鈕事件Click關聯Button2_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
適用於
Font(String, Single, FontStyle, GraphicsUnit, Byte, Boolean)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- 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
FontFamily對於新的 Font。
- emSize
- Single
新字型在參數指定的 unit 單位內的 em-size 。
- unit
- GraphicsUnit
新字體的介紹 GraphicsUnit 。
例外狀況
emSize 小於或等於0、值無限大,或不是一個有效的數值。
備註
參數 gdiCharSet 取自 Windows SDK 標頭檔 WinGDI.h 中定義的清單。 若參數 familyName 指定未安裝於執行該應用程式的機器或不支援的字型,則改為 Microsoft Sans Serif 字型。
另請參閱
適用於
Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte, Boolean)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- 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
新的 FontFamilyFont.
- emSize
- Single
新字型在參數指定的 unit 單位內的 em-size 。
- unit
- GraphicsUnit
新字體的介紹 GraphicsUnit 。
- gdiVerticalFont
- Boolean
布爾值,指出新字型是否衍生自 GDI 垂直字型。
例外狀況
emSize 小於或等於0、值無限大,或不是一個有效的數值。
family 是 null
備註
參數 gdiCharSet 取自 Windows SDK 標頭檔 WinGDI.h 中定義的清單。
適用於
Font(FontFamily, Single, FontStyle, GraphicsUnit, Byte)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- 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
新的 FontFamilyFont.
- emSize
- Single
新字型在參數指定的 unit 單位內的 em-size 。
- unit
- GraphicsUnit
新字體的介紹 GraphicsUnit 。
例外狀況
emSize 小於或等於0、值無限大,或不是一個有效的數值。
family 為 null。
備註
參數 gdiCharSet 取自 Windows SDK 標頭檔 WinGDI.h 中定義的清單。
適用於
Font(String, Single, FontStyle, GraphicsUnit)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- 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
FontFamily對於新的 Font。
- emSize
- Single
新字型在參數指定的 unit 單位內的 em-size 。
- unit
- GraphicsUnit
新字體的介紹 GraphicsUnit 。
例外狀況
emSize 小於或等於0、值無限大或不是一個有效的數值。
範例
以下程式碼範例示範如何使用 Font 建構子。 此範例的設計目的是要與 Windows Forms 搭配使用。 執行此範例時,將此程式碼貼入包含名為 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 Forms 應用程式支援 TrueType 字型,而且對 OpenType 字型的支援有限。 若參數 familyName 指定未安裝於執行該應用程式的機器或不支援的字型,則改為 Microsoft Sans Serif 字型。
適用於
Font(FontFamily, Single, FontStyle, GraphicsUnit)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- 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
新的 FontFamilyFont.
- emSize
- Single
新字型在參數指定的 unit 單位內的 em-size 。
- unit
- GraphicsUnit
新字體的介紹 GraphicsUnit 。
例外狀況
emSize 小於或等於0、值無限大,或不是一個有效的數值。
family 為 null。
適用於
Font(String, Single, FontStyle, GraphicsUnit, Byte)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- 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
FontFamily對於新的 Font。
- emSize
- Single
新字型在參數指定的 unit 單位內的 em-size 。
- unit
- GraphicsUnit
新字體的介紹 GraphicsUnit 。
例外狀況
emSize 小於或等於0、值無限大,或不是一個有效的數值。
備註
參數 gdiCharSet 取自 Windows SDK 標頭檔 WinGDI.h 中定義的清單。 Windows Forms 應用程式支援 TrueType 字型,而且對 OpenType 字型的支援有限。 若參數 familyName 指定未安裝於執行該應用程式的機器或不支援的字型,則改為 Microsoft Sans Serif 字型。
另請參閱
適用於
Font(String, Single, FontStyle)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- 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
FontFamily對於新的 Font。
- emSize
- Single
新字型的 em-size,以點為單位。
例外狀況
emSize 小於或等於0、值無限大,或不是一個有效的數值。
備註
所得字型的屬性設定 Unit 為 Point。 Windows Forms 應用程式支援 TrueType 字型,而且對 OpenType 字型的支援有限。 若參數 familyName 指定未安裝於執行該應用程式的機器或不支援的字型,則改為 Microsoft Sans Serif 字型。
適用於
Font(FontFamily, Single, GraphicsUnit)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
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
新的 FontFamilyFont.
- emSize
- Single
新字型在參數指定的 unit 單位內的 em-size 。
- unit
- GraphicsUnit
新字體的介紹 GraphicsUnit 。
例外狀況
family 為 null。
emSize 小於或等於0、值無限大,或不是一個有效的數值。
備註
所得字型的屬性設定 Style 為 FontStyle.Regular。
適用於
Font(FontFamily, Single, FontStyle)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- 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
新的 FontFamilyFont.
- emSize
- Single
新字型的 em-size,以點為單位。
例外狀況
emSize 小於或等於0、值無限大,或不是一個有效的數值。
family 為 null。
範例
以下程式碼範例示範如何將按鈕屬性設定 Font 為新的粗體 Font。 此範例設計用於包含名為 Button1的按鈕的 Windows 表單。 將以下程式碼貼到表單中,並將方法與按鈕事件Click關聯Button1_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
備註
適用於
Font(String, Single)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- 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
FontFamily對於新的 Font。
- emSize
- Single
新字型的 em-size,以點為單位。
例外狀況
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 Forms 應用程式支援 TrueType 字型,而且對 OpenType 字型的支援有限。 若參數 familyName 指定未安裝於執行該應用程式的機器或不支援的字型,則改為 Microsoft Sans Serif 字型。
適用於
Font(FontFamily, Single)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- 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
新的 FontFamilyFont.
- emSize
- Single
新字型的 em-size,以點為單位。
例外狀況
emSize 小於或等於0、值無限大,或不是一個有效的數值。
備註
所得字型的屬性設定 Style 為 , Regular 屬性 Unit 設定為 Point。
適用於
Font(String, Single, GraphicsUnit)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
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
FontFamily對於新的 Font。
- emSize
- Single
新字型在參數指定的 unit 單位內的 em-size 。
- unit
- GraphicsUnit
新字體的介紹 GraphicsUnit 。
例外狀況
emSize 小於或等於0、值無限大,或不是一個有效的數值。
備註
所得字型的屬性設定 Style 為 FontStyle.Regular。