Font Property

Purpose

Returns or sets a Font object.

Syntax

object.Font [ = font ]

object: visible OCX objects

Description

Use the Font property of an object to identify a specific Font object whose properties you want to use. The Font property can also be used to assign a new Font object to the Ocx object. Usually, assigning a new object to an object variable requires the Set command.

For example, the following code changes the Bold property setting of a Font object identified by the Font property of a TextBox object.

Example

OpenW 1 ': Win_1.Font.Name = "Courier New"

Text 10, 10, "This is the native Window font"

Ocx Label lbl = "This is the Label font", 10, 25, 200, 15 : lbl.Font.Name = "Times New Roman"

Ocx Command cmd1 = "Match Font to that of Window", 15, 45, 90, 36 : cmd1.Font.Name = "Arial" cmd1.WinStyle = cmd1.WinStyle | BS_MULTILINE

Ocx Command cmd2 = "Make Label Bold", 115, 45, 90, 36 : cmd2.Font.Name = "Arial" cmd2.WinStyle = cmd2.WinStyle | BS_MULTILINE

Do : Sleep  : Until Win_1 Is Nothing

 

Sub cmd1_Click

If lbl.FontName = "Times New Roman" // lbl.Font.Name and lbl.FontName are interchangeable

Set lbl.Font = Win_1.Font  // this copies all Font characteristics, not just Name and resets Bold if set, so...

cmd2.Caption = "Make Label Bold"

cmd1.Caption = "Restore original font to Label"

Else

lbl.FontName = "Times New Roman"

cmd1.Caption = "Match Font to that of Window"

EndIf

EndSub

 

Sub cmd2_Click

If lbl.Font.Bold = True

lbl.FontBold = False // lbl.Font.Bold and lbl. FontBold are interchangeable

cmd2.Caption = "Make Label Bold"

Else

lbl.Font.Bold = True

cmd2.Caption = "Make Label Normal Weight"

EndIf

EndSub

Remarks

The preferred way to setting font attributes is by using a particular font attribute property, like FontBold. The generated code is smaller and faster for each saved dot.

See Also

Font Object, FontBold, FontItalic, FontName, FontSize, FontStrikethru, FontTransparent, FontUnderline, SetFont.

{Created by Sjouke Hamstra; Last updated: 06/10/2014 by James Gaite}