This documentation is archived and is not being maintained.

LogFont Class

Defines the characteristics of a font for creating rotated text effects.

Namespace:  Microsoft.WindowsCE.Forms
Assembly:  Microsoft.WindowsCE.Forms (in Microsoft.WindowsCE.Forms.dll)

public class LogFont

This class corresponds to the native Windows CE LOGFONT (logical font) structure, which provides the ability to create angled and other text effects. Values for some of the LogFont fields are defined by the enumerations described in the following table.

Enumeration

Description

CharSet

Specifies the character set of the font.

ClipPrecision

Specifies how to clip characters that are partially outside the clipping region.

PitchAndFamily

Specifies the font family that describes the font in a general way.

OutPrecision

Specifies how closely the output must match the requested height, weight, and other attributes of a font.

Quality

Specifies the quality of the font.

Weight

Specifies the weight of the font.

To create rotated text, create an instance of the LogFont class and set the Escapement field to the desired rotation angle. Note that Escapement specifies the angle in tenths of a degree; for a 45-degree angle you would specify 450.

The Escapement field specifies both the escapement and orientation. You should set Escapement and Orientation to the same value.

The font mapper, a component of Windows CE, finds the physical font that most closely matches values specified for the Height and Weight fields.

The following code example shows how to define a LogFont so that the text runs diagonally across the screen.

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

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Compact Framework

Supported in: 3.5, 2.0
Show: