Font 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
多載
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
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 Form 搭配使用。 將下列程式代碼貼到表單中,並將 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)
- 來源:
- 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
新 Font 之 FontFamily 的字串表示。
- emSize
- Single
新字型的 Em 大小,以 unit
參數所指定的單位計算。
- 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。
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
新 Font 的 FontFamily。
- emSize
- Single
新字型的 Em 大小,以 unit
參數所指定的單位計算。
- 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。
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
新 Font 的 FontFamily。
- emSize
- Single
新字型的 Em 大小,以 unit
參數所指定的單位計算。
- unit
- GraphicsUnit
新字型的 GraphicsUnit。
例外狀況
emSize
小於或等於 0、評估為無限,或為無效數字。
family
為 null
。
備註
參數gdiCharSet
會從 Windows SDK 頭檔 WinGDI.h 中所定義的清單中取得值。
適用於
Font(String, Single, FontStyle, GraphicsUnit)
- 來源:
- 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
新 Font 之 FontFamily 的字串表示。
- emSize
- Single
新字型的 Em 大小,以 unit
參數所指定的單位計算。
- 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。
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
新 Font 的 FontFamily。
- emSize
- Single
新字型的 Em 大小,以 unit
參數所指定的單位計算。
- unit
- GraphicsUnit
新字型的 GraphicsUnit。
例外狀況
emSize
小於或等於 0、評估為無限,或為無效數字。
family
為 null
。
適用於
Font(String, Single, FontStyle, GraphicsUnit, Byte)
- 來源:
- 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
新 Font 之 FontFamily 的字串表示。
- emSize
- Single
新字型的 Em 大小,以 unit
參數所指定的單位計算。
- 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。
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
新 Font 之 FontFamily 的字串表示。
- emSize
- Single
新字型的 Em 大小 (以點計算)。
例外狀況
emSize
小於或等於 0、評估為無限,或為無效數字。
備註
產生的字型將其 Unit 屬性設定為 Point。 Windows Forms 應用程式支援 TrueType 字型,且對 OpenType 字型的支援有限。 familyName
如果 參數指定未安裝在執行應用程式或不支援之電腦上的字型,則會取代 Microsoft Sans Serif。
適用於
Font(FontFamily, Single, GraphicsUnit)
- 來源:
- 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
新 Font 的 FontFamily。
- emSize
- Single
新字型的 Em 大小,以 unit
參數所指定的單位計算。
- unit
- GraphicsUnit
新字型的 GraphicsUnit。
例外狀況
family
為 null
。
emSize
小於或等於 0、評估為無限,或為無效數字。
備註
產生的字型將其 Style 屬性設定為 FontStyle.Regular。
適用於
Font(FontFamily, Single, FontStyle)
- 來源:
- 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
新 Font 的 FontFamily。
- emSize
- Single
新字型的 Em 大小 (以點計算)。
例外狀況
emSize
小於或等於 0、評估為無限,或為無效數字。
family
為 null
。
範例
下列程式代碼範例示範如何將按鈕的 屬性設定 Font 為新的粗體樣式 Font。 此範例的設計目的是要與 Windows Form 搭配使用,其中包含名為的 Button1
按鈕。 將下列程式代碼貼到表單中,並將 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
備註
適用於
Font(String, Single)
- 來源:
- 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
新 Font 之 FontFamily 的字串表示。
- emSize
- Single
新字型的 Em 大小 (以點計算)。
例外狀況
emSize
小於或等於 0、評估為無限,或為無效數字。
範例
下列程式代碼範例示範如何使用 建 Font 構函式。 此範例的設計目的是要與 Windows Form 搭配使用,而且需要 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。
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
新 Font 的 FontFamily。
- emSize
- Single
新字型的 Em 大小 (以點計算)。
例外狀況
emSize
小於或等於 0、評估為無限,或為無效數字。
備註
產生的字型將其 Style 屬性設定為 Regular ,且其 Unit 屬性設定為 Point。
適用於
Font(String, Single, GraphicsUnit)
- 來源:
- 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
新 Font 之 FontFamily 的字串表示。
- emSize
- Single
新字型的 Em 大小,以 unit
參數所指定的單位計算。
- unit
- GraphicsUnit
新字型的 GraphicsUnit。
例外狀況
emSize
小於或等於 0、評估為無限,或為無效數字。
備註
產生的字型將其 Style 屬性設定為 FontStyle.Regular。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應