Bold, Italic, Size, StrikeThrough, Underline, Weight Properties

Applies To

Font object.

Description

Specifies the visual attributes of text on a displayed or printed form.

Syntax

object.Bold [= Boolean]

object.Italic [= Boolean]

object.Size [= Currency]

object.StrikeThrough [= Boolean]

object.Underline [= Boolean]

object.Weight [= Integer]

The Bold, Italic, Size, StrikeThrough, Underline, and Weight property syntaxes have these parts:

Part

Description

object

Required. A valid object name.

Boolean

Optional. Specifies the font style.

Currency

Optional. A number indicating the font size.

Integer

Optional. Specifies the font style.


The settings for Boolean are:

Value

Description

True

The text has the specified attribute (that is bold, italic, size, strikethrough or underline marks, or weight).

False

The text does not have the specified attribute (default).


The Weight property accepts values from 0 to 1000. A value of zero allows the system to pick the most appropriate weight. A value from 1 to 1000 indicates a specific weight, where 1 represents the lightest type and 1000 represents the darkest type.

Remarks

These properties define the visual characteristics of text. The Bold property determines whether text is normal or bold. The Italic property determines whether text is normal or italic. The Size property determines the height, in points, of displayed text. The Underline property determines whether text is underlined. The StrikeThrough property determines whether the text appears with strikethrough marks. The Weight property determines the darkness of the type.

The font's appearance on screen and in print may differ, depending on your computer and printer. If you select a font that your system can't display with the specified attribute or that isn't installed, Windows substitutes a similar font. The substitute font will be as similar as possible to the font originally requested.

Changing the value of Bold also changes the value of Weight. Setting Bold to True sets Weight to 700; setting Bold to False sets Weight to 400. Conversely, setting Weight to anything over 550 sets Bold to True; setting Weight to 550 or less sets Bold to False.

The default point size is determined by the operating system.

See Also

Name property.

Example

The following example demonstrates a Font object and the Bold, Italic, Size, StrikeThrough, Underline, and Weight properties related to fonts. You can manipulate font properties of an object directly or by using an alias, as this example also shows.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A Label named Label1.
  • Four ToggleButton controls named ToggleButton1 through ToggleButton4.
  • A second Label and a TextBox named Label2 and TextBox1.
    Dim MyFont As StdFont
    
    Private Sub ToggleButton1_Click()
        If ToggleButton1.Value = True Then
            MyFont.Bold = True            'Using MyFont alias to control font
            ToggleButton1.Caption = "Bold On"
            MyFont.Size = 22              'Increase the font size.
        Else
            MyFont.Bold = False
            ToggleButton1.Caption = "Bold Off"
            MyFont.Size = 8               'Return font size to initial size.
        End If
        
        TextBox1.Text = Str(MyFont.Weight)  'Bold and Weight are related.
    End Sub
    
    Private Sub ToggleButton2_Click()
        If ToggleButton2.Value = True Then
            Label1.Font.Italic = True            'Using Label1.Font directly
            ToggleButton2.Caption = "Italic On"
        Else
            Label1.Font.Italic = False
            ToggleButton2.Caption = "Italic Off"
        End If
    End Sub
    
    Private Sub ToggleButton3_Click()
        If ToggleButton3.Value = True Then
            Label1.Font.Strikethrough = True   'Using Label1.Font directly
            ToggleButton3.Caption = "StrikeThrough On"
        Else
            Label1.Font.Strikethrough = False
            ToggleButton3.Caption = "StrikeThrough Off"
        End If
    End Sub
    
    Private Sub ToggleButton4_Click()
        If ToggleButton4.Value = True Then
            MyFont.Underline = True   'Using MyFont alias for Label1.Font
            ToggleButton4.Caption = "Underline On"
        Else
            Label1.Font.Underline = False
            ToggleButton4.Caption = "Underline Off"
        End If
    End Sub
    
    Private Sub UserForm_Initialize()
        Set MyFont = Label1.Font
        
        ToggleButton1.Value = True
        ToggleButton1.Caption = "Bold On"
        
        Label1.AutoSize = True        'Set size of Label1
        Label1.AutoSize = False
            
        ToggleButton2.Value = False
        ToggleButton2.Caption = "Italic Off"
        
        ToggleButton3.Value = False
        ToggleButton3.Caption = "StrikeThrough Off"
            
        ToggleButton4.Value = False
        ToggleButton4.Caption = "Underline Off"
        
        Label2.Caption = "Font Weight"
        TextBox1.Text = Str(Label1.Font.Weight)
        TextBox1.Enabled = False
    
    End Sub