全部显示

FontName 属性

       

使用 FontName 属性可以在以下情况中为文本指定字体

String 型,可读/写。

expression.FontName

expression   必需。返回“Applies To”列表中的一个对象的表达式。

说明

FontName 属性设置是显示文本所用的字体名称。

对于窗体及报表上的控件,可以使用属性表Visual Basic 来设置该属性。

也可以单击“格式(窗体/报表)”工具栏中的“字体”框来设置该属性。

使用控件的默认控件样式或在 Visual Basic 中使用 DefaultControl 方法可以设置该属性的默认值。

对于报表,只能在 OnPrint 事件属性设置所指定的事件过程或宏中使用该设置。

在 Visual Basic 中,可以使用窗体或报表名称的一个字符串表达式设置 FontName 属性。

字体是否可用取决于系统及打印机。如果选择了某种系统不能显示或并未安装的字体,Windows 将用另一种相似的字体替代。

示例

以下示例使用 Print 方法来显示名为“报表1”的报表上的文本。它使用 TextWidthTextHeight 方法,使文本在垂直和水平方向上居中。

Private Sub Detail_Format(Cancel As Integer, _
        FormatCount As Integer)
    Dim rpt as Report
    Dim strMessage As String
    Dim intHorSize As Integer, intVerSize As Integer

    Set rpt = Me
    strMessage = "DisplayMessage"
    With rpt
        'Set scale to pixels, and set FontName and
        'FontSize properties.
        .ScaleMode = 3
        .FontName = "Courier"
        .FontSize = 24
    End With
    ' Horizontal width.
    intHorSize = Rpt.TextWidth(strMessage)
    ' Vertical height.
    intVerSize = Rpt.TextHeight(strMessage)
    ' Calculate location of text to be displayed.
    Rpt.CurrentX = (Rpt.ScaleWidth/2) - (intHorSize/2)
    Rpt.CurrentY = (Rpt.ScaleHeight/2) - (intVerSize/2)
    ' Print text on Report object.
    Rpt.Print strMessage
End Sub