Font.GetHeight 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回此字型的行距。
多載
| 名稱 | Description |
|---|---|
| GetHeight() |
傳回此字型的行距,以像素為單位。 |
| GetHeight(Graphics) |
回傳此字型的行距,以指定 Graphics字型的當前單位。 |
| GetHeight(Single) |
當繪製到指定垂直解析度的裝置時,回傳此高度 Font (像素)。 |
GetHeight()
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
傳回此字型的行距,以像素為單位。
public:
float GetHeight();
public float GetHeight();
member this.GetHeight : unit -> single
Public Function GetHeight () As Single
傳回
此字型的行距,以像素為單位。
備註
a Font 的行距是指兩行連續文字基線之間的垂直距離。 因此,行距包含行之間的空格以及字元本身的高度。
若 Unit 字型屬性設定為非 GraphicsUnit.Pixel,則以螢幕顯示的垂直解析度計算高度(像素數)。 例如,假設字型單位是英吋,字型大小為0.3。 此外,假設針對對應的字型系列,em 高度為 2048,而行距為 2355。 對於垂直解析度為每英吋 96 點的螢幕顯示器,您可以計算高度,如下所示:
2355*(0.3/2048)*96 = 33.11719
適用於
GetHeight(Graphics)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
回傳此字型的行距,以指定 Graphics字型的當前單位。
public:
float GetHeight(System::Drawing::Graphics ^ graphics);
public float GetHeight(System.Drawing.Graphics graphics);
member this.GetHeight : System.Drawing.Graphics -> single
Public Function GetHeight (graphics As Graphics) As Single
參數
傳回
此字型的行距,以像素為單位。
例外狀況
graphics 為 null。
範例
以下程式碼範例是為 Windows 表單設計,並需要 PaintEventArgse,這是事件處理器的 Paint 參數。 程式代碼會執行下列動作:
public:
void GetHeight_Example( PaintEventArgs^ e )
{
// Create a Font object.
System::Drawing::Font^ myFont = gcnew System::Drawing::Font( "Arial",16 );
//Draw text to the screen with myFont.
e->Graphics->DrawString( "This is the first line", myFont, Brushes::Black, PointF(0,0) );
//Get the height of myFont.
float height = myFont->GetHeight( e->Graphics );
//Draw text immediately below the first line of text.
e->Graphics->DrawString( "This is the second line", myFont, Brushes::Black, PointF(0,height) );
}
public void GetHeight_Example(PaintEventArgs e)
{
// Create a Font object.
Font myFont = new Font("Arial", 16);
//Draw text to the screen with myFont.
e.Graphics.DrawString("This is the first line",myFont,
Brushes.Black, new PointF(0, 0));
//Get the height of myFont.
float height = myFont.GetHeight(e.Graphics);
//Draw text immediately below the first line of text.
e.Graphics.DrawString(
"This is the second line",
myFont,
Brushes.Black,
new PointF(0, height));
}
Public Sub GetHeight_Example(ByVal e As PaintEventArgs)
' Create a Font object.
Dim myFont As New Font("Arial", 16)
'Draw text to the screen with myFont.
e.Graphics.DrawString("This is the first line", myFont, _
Brushes.Black, New PointF(0, 0))
'Get the height of myFont.
Dim height As Single = myFont.GetHeight(e.Graphics)
'Draw text immediately below the first line of text.
e.Graphics.DrawString("This is the second line", myFont, _
Brushes.Black, New PointF(0, height))
End Sub
備註
a Font 的行距是指兩行連續文字基線之間的垂直距離。 因此,行距包含行之間的空格以及字元本身的高度。
若 Unit 字型屬性設定為非 GraphicsUnit.Pixel,則高度(像素)會利用指定 Graphics 物件的垂直解析度計算。 例如,假設字型單位是英吋,字型大小為0.3。 此外,假設針對對應的字型系列,em 高度為 2048,而行距為 2355。 若 Graphics 物體的 Unit 屬性值為 , GraphicsUnit.Pixel 屬性 DpiY 值為每英吋 96 點,則高度計算方式如下:
2355*(0.3/2048)*96 = 33.1171875
繼續用同一例子,假設 Unit 物件的 Graphics 性質設為 , GraphicsUnit.Millimeter 而非 GraphicsUnit.Pixel。 然後(使用 1 英吋 = 25.4 公厘)的高度,以公厘為單位計算如下:
2355*(0.3/2048)25.4 = 8.762256
另請參閱
適用於
GetHeight(Single)
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
- 來源:
- Font.cs
當繪製到指定垂直解析度的裝置時,回傳此高度 Font (像素)。
public:
float GetHeight(float dpi);
public float GetHeight(float dpi);
member this.GetHeight : single -> single
Public Function GetHeight (dpi As Single) As Single
參數
- dpi
- Single
垂直解析度,以每英吋點為單位,用來計算字型的高度。
傳回
這個 Font的高度,以像素為單位。
備註
若 Unit 字型屬性設定為非 GraphicsUnit.Pixel,則以螢幕顯示的垂直解析度計算高度(像素數)。 例如,假設字型單位是英吋,字型大小為0.3。 此外,假設針對對應的字型系列,em 高度為 2048,而行距為 2355。 如果指定的垂直解析度為每英吋 96 點,則高度會計算如下:
2355*(0.3/2048)*96 = 33.1171875