FontName 屬性

此頁沒有內(nèi)容條目
內(nèi)容

expandtri全部顯示

使用 FontName 屬性可以在以下情況中為文本指定字體。

?在顯示或打印窗體報(bào)表中的控件時。

 

?在報(bào)表中使用 Print 方法時。

String 型,可讀/寫。

expression.FontName

expression     必需。返回“應(yīng)用于”列表中的一個對象的表達(dá)式。

說明

FontName 屬性設(shè)置是顯示文本所用的字體名稱。

對于窗體及報(bào)表上的控件,可以使用屬性表、Visual Basic 來設(shè)置該屬性。

也可以單擊“格式(窗體/報(bào)表)”工具欄中的“字體”框來設(shè)置該屬性。

使用控件的默認(rèn)控件樣式或在 Visual Basic 中使用 DefaultControl 方法可以設(shè)置該屬性的默認(rèn)值。

對于報(bào)表,只能在 OnPrint 事件屬性設(shè)置所指定的事件過程或宏中使用該設(shè)置。

在 Visual Basic 中,可以使用窗體或報(bào)表名稱的一個字符串表達(dá)式設(shè)置 FontName 屬性。

字體是否可用取決于系統(tǒng)及打印機(jī)。如果選擇了某種系統(tǒng)不能顯示或并未安裝的字體,Windows 將用另一種相似的字體替代。

示例

以下示例使用 Print 方法來顯示名為“報(bào)表1”的報(bào)表上的文本。它使用 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