Compartir a través de


LogFont (Clase)

Actualización: noviembre 2007

Define las características de una fuente para crear efectos de texto girado.

Espacio de nombres:  Microsoft.WindowsCE.Forms
Ensamblado:  Microsoft.WindowsCE.Forms (en Microsoft.WindowsCE.Forms.dll)

Sintaxis

'Declaración
Public Class LogFont
'Uso
Dim instance As LogFont
public class LogFont
public ref class LogFont
public class LogFont

Comentarios

Esta clase corresponde a la estructura (fuente lógica) LOGFONT nativa de Windows CE, que proporciona la capacidad para crear texto en ángulo y otros efectos de texto. Las enumeraciones descritas en la tabla siguiente definen los valores para algunos de los campos de LogFont.

Enumeración

Descripción

CharSet

Especifica el juego de caracteres de la fuente.

ClipPrecision

Especifica cómo recortar caracteres que están parcialmente fuera de la zona de recorte.

PitchAndFamily

Especifica la familia de la fuente, la cual describe la fuente de una manera general.

OutPrecision

Especifica qué grado de coincidencia debe existir entre el resultado y los atributos solicitados de una fuente (alto, grosor y otros).

Quality

Especifica la calidad de la fuente.

Weight

Especifica el grosor de la fuente.

Para crear texto girado, cree una instancia de la clase LogFont y asigne al campo Escapement el ángulo de rotación deseado. Observe que Escapement especifica el ángulo en décimas de grado; por ejemplo, para un ángulo de 45 grados, se debería especificar 450.

El campo Escapement especifica el escape y la orientación. Debe asignar a Escapement y Orientation el mismo valor.

El asignador de fuentes, que es un componente de Windows CE, determina la fuente física que mejor se ajusta a los valores especificada para los campos Height y Weight.

Ejemplos

El ejemplo de código siguiente muestra cómo definir LogFont para que el texto se escriba diagonalmente por la pantalla.

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());
        }
    }
}

Jerarquía de herencia

System.Object
  Microsoft.WindowsCE.Forms.LogFont

Seguridad para subprocesos

Todos los miembros static (Shared en Visual Basic) públicos de este tipo son seguros para la ejecución de subprocesos. No se garantiza que los miembros de instancias sean seguros para la ejecución de subprocesos.

Plataformas

Windows CE, Windows Mobile para Smartphone, Windows Mobile para Pocket PC

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Información de versión

.NET Compact Framework

Compatible con: 3.5, 2.0

Vea también

Referencia

LogFont (Miembros)

Microsoft.WindowsCE.Forms (Espacio de nombres)

Otros recursos

Ejemplo Rotated Text Using LogFont