The Font object contains information needed to format text for display in the interface of an application or for printed output.
Dim name As Font
Dim name As [New] StdFont
You frequently identify a Font object using the Font property of an object that displays text (such as a Form object or the Printer object).
You cannot create a Font object using code like Dim X As New Font. If you want to create a Font object, you must use the StdFont object like this:
Dim X As New StdFont
Bold | Bool | get/put | Returns or sets the font style to either bold or non bold. |
CharSet | Short | get/put | Sets or returns the character set used in the font. 0 - Standard Windows characters 2 - The symbol character set. 128 - Double-byte character set (DBCS) unique to the Japanese version of Windows 255 - Extended characters normally displayed by DOS applications. |
Italic | Bool | get/put | Returns or sets the font style to either italic or non-italic. |
Name | String | get/put | Returns or sets the name of a font. |
Size | Currency | get/put | Returns or sets the font size used in points. |
Strikethrough | Bool | get/put | Returns or sets the font style to either strikethrough or non-strikethrough |
Underline | Bool | get/put | Returns or sets the font style to either underlined or non-underlined |
Weight | Short | get/put | Returns or sets the weight of the characters. The weight refers to the thickness of the characters, or the “boldness factor”. The higher the value, the bolder the character. |
_hFont | Handle | Get | Returns the font handle. |
If you put a TextBox control named Text1 on a form, you can dynamically change its Font object to another using the Set statement, as in the following example:
Ocx TextBox Text1 = "Hello", 10, 10, 150, 35 : Text1.BorderStyle = 1
Dim X As New StdFont
X.Bold = True
X.Name = "Arial"
X.Size = 16
X.Strikethrough = True
Set Text1.Font = X
Do : Sleep : Until Me Is Nothing
As an alternative, the following can be used:
Text1.FontBold = True
Text1.FontStrikeThrough = True
Text1.FontSize = 16
More information about fonts can be gleaned through using the GetTextMetrics() API as shown below:
Type TEXTMETRIC
tmHeight As Long
tmAscent As Long
tmDescent As Long
tmInternalLeading As Long
tmExternalLeading As Long
tmAveCharWidth As Long
tmMaxCharWidth As Long
tmWeight As Long
tmOverhang As Long
tmDigitizedAspectX As Long
tmDigitizedAspectY As Long
tmFirstChar As Byte
tmLastChar As Byte
tmDefaultChar As Byte
tmBreakChar As Byte
tmItalic As Byte
tmUnderlined As Byte
tmStruckOut As Byte
tmPitchAndFamily As Byte
tmCharSet As Byte
End Type
Local tm As TEXTMETRIC
OpenW 1 : Win_1.FontName = "Courier New"
~GetTextMetrics(Win_1.hDC, tm)
Print "TextHeight: "; tm.tmHeight
Print "Font Ascent (above baseline):"; tm.tmAscent
Print "Font Descent (below baseline):"; tm.tmDescent
Font Property, Setfont, Freefont, RFont, _Font$
{Created by Sjouke Hamstra; Last updated: 14/01/2015 by James Gaite}