共用方式為


LogFont 類別

定義字型特性,以用於建立旋轉文字效果。

命名空間:  Microsoft.WindowsCE.Forms
組件:  Microsoft.WindowsCE.Forms (在 Microsoft.WindowsCE.Forms.dll 中)

語法

'宣告
Public Class LogFont
'用途
Dim instance As LogFont
public class LogFont
public ref class LogFont
public class LogFont

備註

此類別對應至原生 Windows CE LOGFONT (邏輯字型) 結構,此結構提供建立角度和其他文字效果的功能。部分 LogFont 欄位的值是由下列表格中描述的列舉型別所定義。

列舉型別

說明

CharSet

指定字型的字元集。

ClipPrecision

指定如何裁剪部分位於裁剪區域外的字元。

PitchAndFamily

指定以一般方式描述字型的字型系列。

OutPrecision

指定輸出與所要求之字型高度、粗細和其他屬性的必要相符程度。

Quality

指定字型的品質。

Weight

指定字型的粗細。

若要建立旋轉文字,請建立 LogFont 類別的執行個體,並將 Escapement 欄位設定成所要的旋轉角度。請注意,Escapement 會以度數的 10 倍來指定角度;若角度為 45 度,則應指定 450。

Escapement 欄位可同時指定字體斜度和方向。您應將 EscapementOrientation 設定成相同值。

字型對應器 (Windows CE 的元件) 會尋找最接近 HeightWeight 欄位指定值的實體字型。

範例

下列程式碼範例顯示如何定義 LogFont,才能以對角方式在螢幕上產生文字。

Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.WindowsCE.Forms

Public Class Form1
    Inherits System.Windows.Forms.Form

    ' Declare objects to draw the text.
    Private rotatedFont As System.Drawing.Font
    Private redBrush As SolidBrush

    ' Specify the text to roate, the rotation angle,
    ' and the base font.
    Private rTxt As String = "abc ABC 123"
    Private rAng As Integer = 45

    ' Determine the vertial DPI setting for scaling the font on the
    ' device you use for developing the application. 
    ' You will need this value for properly scaling the font on
    ' devices with a different DPI.
    ' In another application, get the DpiY property from a Graphics object 
    ' on the device you use for application development:
    ' 
    '   Dim g As Graphics = Me.CreateGraphics()
    '   Dim curDPI As Integer = g.DpiY

    Private Const curDPI As Integer = 96

    ' Note that capabilities for rendering a font are 
    ' dependant on the device.
    Private rFnt As String = "Arial"

    Public Sub New()
        MyBase.New()

        ' Display OK button to close application.
        Me.MinimizeBox = False
        Me.Text = "Rotated Font"

        ' Create rotatedFont and redBrush objects in the custructor of
        ' the form so that they can be resued when the form is repainted.
        Me.rotatedFont = CreateRotatedFont(rFnt, rAng)
        Me.redBrush = New SolidBrush(Color.Red)
    End Sub

    ' Method to create a rotated font using a LOGFONT structure.
    Private Function CreateRotatedFont(ByVal fontname As String, _
        ByVal angleInDegrees As Integer) As Font

        Dim logf As LogFont = New Microsoft.WindowsCE.Forms.LogFont

        ' Create graphics object for the form, and obtain
        ' the current DPI value at design time. In this case,
        ' only the vertical resolution is petinent, so the DpiY
        ' property is used. 
        Dim g As Graphics = Me.CreateGraphics

        ' Scale an 18-point font for current screen vertical DPI.
        logf.Height = Fix(-18.0F * g.DpiY / curDPI)

        ' Convert specified rotation angle to tenths of degrees.
        logf.Escapement = (angleInDegrees * 10)

        ' Orientation is the same as Escapement in mobile platforms.
        logf.Orientation = logf.Escapement

        logf.FaceName = fontname

        ' Set LogFont enumerations.
        logf.CharSet = LogFontCharSet.Default
        logf.OutPrecision = LogFontPrecision.Default
        logf.ClipPrecision = LogFontClipPrecision.Default
        logf.Quality = LogFontQuality.ClearType
        logf.PitchAndFamily = LogFontPitchAndFamily.Default

        ' Explicitly dispose any drawing objects created.
        g.Dispose()

        Return System.Drawing.Font.FromLogFont(logf)
    End Function

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        If (Me.rotatedFont Is Nothing) Then
            Return
        End If
        ' Draw the text to the screen using the LogFont, starting at
        ' the specified coordinates on the screen.
        e.Graphics.DrawString(rTxt, Me.rotatedFont, Me.redBrush, _
            75, 125, New StringFormat( _
            (StringFormatFlags.NoWrap Or StringFormatFlags.NoClip)))
    End Sub

    Protected Overrides Sub Dispose(ByVal disposing As Boolean)

        ' Dispose created graphic objects. Although they are 
        ' disposed by the garbage collector when the application
        ' terminates, a good practice is to dispose them when they
        ' are no longer needed.
        Me.redBrush.Dispose()
        Me.rotatedFont.Dispose()
        MyBase.Dispose(disposing)
    End Sub

    Public Shared Sub Main()
        Application.Run(New Form1)
    End Sub
End Class
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.WindowsCE.Forms;

namespace LogFontDemo
{
    public class Form1 : System.Windows.Forms.Form
    {
        // Declare objects to draw the text.
        Font rotatedFont;
        SolidBrush redBrush;

        // Specify the text to roate, the rotation angle,
        // and the base font.
        private string rTxt = "abc ABC 123";
        private int rAng = 45;

    // Determine the vertial DPI setting for scaling the font on the 
    // device you use for developing the application.
    // You will need this value for properly scaling the font on
    // devices with a different DPI.
    // In another application, get the DpiY property from a Graphics object 
    // on the device you use for application development:
    // 
    //   Graphics g = this.CreateGraphics();
    //   int curDPI = g.DpiY;

        private const int curDPI = 96;

        // Note that capabilities for rendering a font are
        // dependant on the device.
        private string rFnt = "Arial";

        public Form1()
        {
            // Display OK button to close application.
            this.MinimizeBox = false;
            this.Text = "Rotated Font";

            // Create rotatedFont and redBrush objects in the custructor of
            // the form so that they can be resued when the form is repainted.
            this.rotatedFont = CreateRotatedFont(rFnt, rAng);
            this.redBrush    = new SolidBrush(Color.Red);
        }

        // Method to create a rotated font using a LOGFONT structure.
        Font CreateRotatedFont(string fontname, int angleInDegrees)
        {
            LogFont logf = new Microsoft.WindowsCE.Forms.LogFont();

            // Create graphics object for the form, and obtain
            // the current DPI value at design time. In this case,
            // only the vertical resolution is petinent, so the DpiY
            // property is used. 

            Graphics g = this.CreateGraphics();
            // Scale an 18-point font for current screen vertical DPI.
            logf.Height = (int)(-18f * g.DpiY / curDPI);

            // Convert specified rotation angle to tenths of degrees.  
            logf.Escapement = angleInDegrees * 10;

            // Orientation is the same as Escapement in mobile platforms.
            logf.Orientation = logf.Escapement;

            logf.FaceName = fontname;

            // Set LogFont enumerations.
            logf.CharSet        = LogFontCharSet.Default;
            logf.OutPrecision   = LogFontPrecision.Default;
            logf.ClipPrecision  = LogFontClipPrecision.Default;
            logf.Quality        = LogFontQuality.ClearType;
            logf.PitchAndFamily = LogFontPitchAndFamily.Default;

            // Explicitly dispose any drawing objects created.
            g.Dispose();

            return Font.FromLogFont(logf);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            if(this.rotatedFont == null)
                return;

            // Draw the text to the screen using the LogFont, starting at
            // the specified coordinates on the screen.
            e.Graphics.DrawString(rTxt,
                this.rotatedFont,
                this.redBrush,
                75,
                125,
                new StringFormat(StringFormatFlags.NoWrap |
                     StringFormatFlags.NoClip));
        }

        protected override void Dispose(bool disposing)
        {

            // Dispose created graphic objects. Although they are 
            // disposed by the garbage collector when the application
            // terminates, a good practice is to dispose them when they
            // are no longer needed.
            this.redBrush.Dispose();
            this.rotatedFont.Dispose();
            base.Dispose(disposing);
        }

        static void Main()
        {
            Application.Run(new Form1());
        }
    }
}

繼承階層架構

System.Object
  Microsoft.WindowsCE.Forms.LogFont

執行緒安全

這個型別的任何 Public static (在 Visual Basic 中為 Shared) 成員都具備執行緒安全。並非所有的執行個體成員都是安全執行緒。

平台

Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Compact Framework

支援版本:3.5、2.0

請參閱

參考

LogFont 成員

Microsoft.WindowsCE.Forms 命名空間

其他資源

使用 LogFont 的旋轉文字範例