當前位置: 首頁>>代碼示例>>C#>>正文


C# Font.GetHeight方法代碼示例

本文整理匯總了C#中System.Drawing.Font.GetHeight方法的典型用法代碼示例。如果您正苦於以下問題:C# Font.GetHeight方法的具體用法?C# Font.GetHeight怎麽用?C# Font.GetHeight使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Drawing.Font的用法示例。


在下文中一共展示了Font.GetHeight方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetHeight_Example

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));
}
開發者ID:.NET開發者,項目名稱:System.Drawing,代碼行數:20,代碼來源:Font.GetHeight

示例2: Main

//引入命名空間
using System;
using System.Drawing;
using System.Windows.Forms;
   
class TextOnBaseline: Form{
     public static void Main() {
          Application.Run(new TextOnBaseline());
     }
     public TextOnBaseline() {
          ResizeRedraw = true; 
     }
     protected override void OnPaint(PaintEventArgs pea) {
          DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
     }
     protected void DoPage(Graphics grfx, Color clr, int cx, int cy) {
          float yBaseline = cy / 2;
          Pen   pen       = new Pen(clr);
   
          grfx.DrawLine(pen, 0, yBaseline, cx, yBaseline);
   
          Font font = new Font("Times New Roman", 144);
   
          float cyLineSpace = font.GetHeight(grfx);
          int   iCellSpace  = font.FontFamily.GetLineSpacing(font.Style);
          int   iCellAscent = font.FontFamily.GetCellAscent(font.Style);
          float cyAscent    = cyLineSpace * iCellAscent / iCellSpace;
   
          grfx.DrawString("Baseline", font, new SolidBrush(clr),
                          0, yBaseline - cyAscent);
     }
}
開發者ID:C#程序員,項目名稱:System.Drawing,代碼行數:32,代碼來源:Font.GetHeight


注:本文中的System.Drawing.Font.GetHeight方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。