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)
Syntax
'Declaration
Public Class LogFont
'Usage
Dim instance As LogFont
public class LogFont
public ref class LogFont
public class LogFont
public class LogFont
Remarks
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 |
---|---|
Specifies the character set of the font. |
|
Specifies how to clip characters that are partially outside the clipping region. |
|
Specifies the font family that describes the font in a general way. |
|
Specifies how closely the output must match the requested height, weight, and other attributes of a font. |
|
Specifies the quality of the font. |
|
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.
Example
The following code example shows how to define a LogFont so that the text runs diagonally across the screen.
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Imports Microsoft.WindowsCE.Forms
Public Class Form1
Inherits System.Windows.Forms.Form
' Sets screen resolution for targeted device.
' If used on high resolution devices with a
' DPI of 192, the font will be scaled accordingly.
Private Const DPISETTING As Integer = 96
Private rotatedFont As Font
Private redBrush As SolidBrush
Public Sub New()
' Display OK button to close application.
Me.MinimizeBox = False
Me.Text = "Rotated Font"
' Create Font and Brush objects in the constructor,
' so they can be resued when the form is repainted.
Me.rotatedFont = CreateRotatedFont("Tahoma", 45)
Me.redBrush = New SolidBrush(Color.Red)
End Sub
' Create an rotated font using a LOGFONT structure.
Function CreateRotatedFont(ByVal fontname As String, ByVal angleInDegrees As Integer) As Font
Dim lf As New LogFont()
' Create graphics object for the form.
Dim g As Graphics = Me.CreateGraphics()
' Scale a 12 point font for current screen DPI.
lf.Height = Fix(- 16F * g.DpiY / DPISETTING)
' Convert rotation angle to tenths of degrees.
lf.Escapement = angleInDegrees * 10
' Orientation is the same as
' Escapement in mobile platforms.
lf.Orientation = lf.Escapement
lf.Width = 0
lf.Weight = 0
lf.Italic = 0
lf.Underline = 0
lf.StrikeOut = 0
lf.CharSet = LogFontCharSet.Default
lf.OutPrecision = LogFontPrecision.Default
lf.ClipPrecision = LogFontClipPrecision.Default
lf.Quality = LogFontQuality.ClearType
lf.PitchAndFamily = LogFontPitchAndFamily.Default
lf.FaceName = fontname
Return System.Drawing.Font.FromLogFont(lf)
' Explicitly dispose any drawing objects created.
g.Dispose()
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 specified coordinates on the screen.
e.Graphics.DrawString("abc ABC 123", Me.rotatedFont, Me.redBrush, 10, 125, New StringFormat(StringFormatFlags.NoWrap Or StringFormatFlags.NoClip))
End Sub
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
MyBase.Dispose(disposing)
' Dispose created graphic objects.
' Although 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()
End Sub
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
{
// Sets screen resolution for targeted device.
// If used on high resolution devices with a
// DPI of 192, the font will be scaled accordingly.
const int DPISETTING = 96;
Font rotatedFont;
SolidBrush redBrush;
public Form1()
{
// Display OK button to close application.
this.MinimizeBox = false;
this.Text = "Rotated Font";
// Create Font and Brush objects in the constructor,
// so they can be resued when the form is repainted.
this.rotatedFont = CreateRotatedFont("Tahoma", 45);
this.redBrush = new SolidBrush(Color.Red);
}
// Create an rotated font using a LOGFONT structure.
Font CreateRotatedFont(string fontname, int angleInDegrees)
{
LogFont lf = new LogFont();
// Create graphics object for the form.
Graphics g = this.CreateGraphics();
// Scale a 12 point font for current screen DPI.
lf.Height = (int)(-16f * g.DpiY / DPISETTING);
// Convert rotation angle to tenths of degrees.
lf.Escapement = angleInDegrees * 10;
// Orientation is the same as
// Escapementin mobile platforms.
lf.Orientation = lf.Escapement;
lf.Width = 0;
lf.Weight = 0;
lf.Italic = 0;
lf.Underline = 0;
lf.StrikeOut = 0;
lf.CharSet = LogFontCharSet.Default;
lf.OutPrecision = LogFontPrecision.Default;
lf.ClipPrecision = LogFontClipPrecision.Default;
lf.Quality = LogFontQuality.ClearType;
lf.PitchAndFamily = LogFontPitchAndFamily.Default;
lf.FaceName = fontname;
return Font.FromLogFont(lf);
// Explicitly dispose any drawing objects created.
g.Dispose();
}
protected override void OnPaint(PaintEventArgs e)
{
if(this.rotatedFont == null)
return;
// Draw the text to the screen using the LogFont
// Starting at specified coordinates on the screen.
e.Graphics.DrawString("abc ABC 123",
this.rotatedFont,
this.redBrush,
10,
125,
new StringFormat(StringFormatFlags.NoWrap |
StringFormatFlags.NoClip));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
// Dispose created graphic objects.
// Although 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();
}
static void Main()
{
Application.Run(new Form1());
}
}
}
Inheritance Hierarchy
System.Object
Microsoft.WindowsCE.Forms.LogFont
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms
Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Version Information
.NET Compact Framework
Supported in: 2.0
See Also
Reference
LogFont Members
Microsoft.WindowsCE.Forms Namespace