Font Size : Font « 2D Graphics « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » 2D Graphics » Font 
17.36.4.Font Size
Imports System.Globalization
Imports System.Text
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Drawing.Text
Imports System
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class FontSizeDemo
   public Shared Sub Main
        Application.Run(New FontSizesForm)
   End Sub
End class


Public Class FontSizesForm
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()

        InitializeComponent()

    End Sub

    Private components As System.ComponentModel.IContainer

    Friend WithEvents listBox1 As System.Windows.Forms.ListBox
    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.listBox1 = New System.Windows.Forms.ListBox()
        Me.SuspendLayout()
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(560182)
        Me.Name = "FontSizesForm"
        Me.Text = "FontSizesForm"
        Me.ResumeLayout(False)

    End Sub

    Private Function GetPixelsFromPoints(ByVal points As Single, ByVal dpi As SingleAs Single
        Return (dpi * points72
    End Function

    Private Function GetInchesFromPoints(ByVal points As Single, ByVal dpi As SingleAs Single
        Return GetPixelsFromPoints(points, dpi/ dpi
    End Function

    Private Function GetPixelsFromDesignUnits(ByVal designUnits As Single, ByVal font As Font, ByVal dpi As SingleAs Single
        Dim scale As Single = GetPixelsFromPoints(font.Size, dpi/ font.FontFamily.GetEmHeight(font.Style)
        Return designUnits * scale
    End Function

    Private Function GetPointsFromPixels(ByVal pixels As Single, ByVal dpi As SingleAs Single
        Return (pixels * 72/ dpi
    End Function


    Private Sub FontSizesForm_Load(ByVal sender As Object, ByVal e As System.EventArgsHandles MyBase.Load
        Dim As Graphics = Me.CreateGraphics()

        Console.WriteLine("Font.Name=                       {0}", Me.Font.Name)
        Console.WriteLine("Font.FontFamly.Name=             {0}", Me.Font.FontFamily.Name)
        Console.WriteLine("Font.Size=                       {0} {1}s (specified Unit)", Me.Font.Size, Me.Font.Unit.ToString())
        Console.WriteLine("Font.Height=                     {0} Pixels", Me.Font.Height)
        Console.WriteLine("Font.GetHeight=                  {0} Pixels", Me.Font.GetHeight(g))
        Console.WriteLine("Font.SizeInPoints=               {0} Points", Me.Font.SizeInPoints.ToString())
        Console.WriteLine("GetPixels(Font.SizeInPoints)=    {0} Pixels", GetPixelsFromPoints(Me.Font.SizeInPoints, g.DpiY))
        Console.WriteLine("GetInches(Font.SizeInPoints)=    {0} Inches", GetInchesFromPoints(Me.Font.SizeInPoints, g.DpiY))
        Console.WriteLine("Font.FontFamily.GetEmHeight=     {0} Design Units", Me.Font.FontFamily.GetEmHeight(FontStyle.Regular))
        Console.WriteLine("GetPixels(GetEmHeight)=          {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetEmHeight(Me.Font.Style), Me.Font, g.DpiY))
        Console.WriteLine("Font.FontFamily.GetLineSpacing=  {0} Design Units", Me.Font.FontFamily.GetLineSpacing(FontStyle.Regular))
        Console.WriteLine("GetPixels(GetLineSpacing)=       {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetLineSpacing(Me.Font.Style), Me.Font, g.DpiY))
        Console.WriteLine("Font.FontFamily.GetCellAscent=   {0} Design Units", Me.Font.FontFamily.GetCellAscent(FontStyle.Regular))
        Console.WriteLine("GetPixels(GetCellAscent)=        {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetCellAscent(Me.Font.Style), Me.Font, g.DpiY))
        Console.WriteLine("Font.FontFamily.GetCellDescent=  {0} Design Units", Me.Font.FontFamily.GetCellDescent(FontStyle.Regular))
        Console.WriteLine("GetPixels(GetCellDescent)=       {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetCellDescent(Me.Font.Style), Me.Font, g.DpiY))
        Console.WriteLine("Padding=                         {0} Design Units", Me.Font.FontFamily.GetLineSpacing(FontStyle.Regular(Me.Font.FontFamily.GetCellAscent(FontStyle.Regular+ Me.Font.FontFamily.GetCellDescent(FontStyle.Regular)))
        'Console.WriteLine("GetPixels(Padding)=              {0} Pixels", GetPixelsFromDesignUnits(Me.Font.FontFamily.GetLineSpacing(FontStyle.Regular(Me.Font.FontFamily.GetCellAscent(FontStyle.Regular+ Me.Font.FontFamily.GetCellDescent(FontStyle.Regular)), Me.Font, g.DpiY)))
    End Sub
End Class
17.36.Font
17.36.1.Create Font with font name, size and styleCreate Font with font name, size and style
17.36.2.Create Font from FontCreate Font from Font
17.36.3.Set font name, size and styleSet font name, size and style
17.36.4.Font Size
17.36.5.Get Font informationGet Font information
17.36.6.Displaying font metric informationDisplaying font metric information
17.36.7.Use CheckBox to Set FontUse CheckBox to Set Font
17.36.8.Font 3DFont 3D
17.36.9.CellAscent, Descent, EmHeight, LineSpacingCellAscent, Descent, EmHeight, LineSpacing
17.36.10.Use RadioButton to control fontUse RadioButton to control font
17.36.11.Use CheckBox to control fontUse CheckBox to control font
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.