CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2019 开发者帮助

SetFont 方法 (ActiveX)

2024-5-18 17:52| 发布者: admin| 查看: 15| 评论: 0|原作者: admin|来自: AutoCAD

SetFont 方法 (ActiveX)

设置 TextStyle 字体的定义数据。

支持的平台:仅限 Windows

签名

VBA:

object.SetFont Typeface, Bold, Italic, CharSet, PitchAndFamily
对象

类型:TextStyle

此方法应用到的对象。

字体

访问:仅输入

类型:字符串

字体(字体名称)。

大胆

访问:仅输入

类型:布尔

将 设置为粗体。TextStyle

  • True:粗体。TextStyle
  • False:不粗体。TextStyle
斜体的

访问:仅输入

类型:布尔

将 设置为斜体。TextStyle

  • True:为斜体。TextStyle
  • False:不是斜体。TextStyle
字符集

访问:仅输入

类型:

字体的字符集。(请参阅“备注”部分中的可用值。

PitchAndFamily(音高与家庭公寓)

访问:仅输入

类型:

字体的音高和系列定义。(请参阅“备注”部分中的可用值。

返回值 (RetVal)

无返回值。

言论

以下部分提供了用于此方法的常量的定义。若要使用这些常量,请复制所需的定义,并将其粘贴到应用程序的“声明”部分。可以在 Visual Basic 开发环境随附的文件win32api.txt中找到 Microsoft 中可用的常量的完整列表。

CharSet 参数指定字体的字符集。若要在 VB 或 VBA 应用程序中使用以下常量,请将定义复制到代码的“声明”部分。

Public Const ANSI_CHARSET = 0
Public Const DEFAULT_CHARSET = 1
Public Const SYMBOL_CHARSET = 2
Public Const SHIFTJIS_CHARSET = 128
Public Const OEM_CHARSET = 255

PitchAndFamily 参数指定字体的音高和族值。该值由三种不同设置的组合确定。若要提供 PitchAndFamily 值,请从每个类别中选择一个设置,然后使用 OR 运算符将它们组合在一起。前两个类别需要设置;球场和家庭。第三类是 TrueType 标志,仅在指定 TrueType 字体时使用。

若要在 VB 或 VBA 应用程序中使用以下常量,请将定义复制到代码的“声明”部分。

' Pitch Values
Public Const DEFAULT_PITCH = 0
Public Const FIXED_PITCH = 1
Public Const VARIABLE_PITCH = 2
' Family Values
Public Const FF_DONTCARE = 0    '  Don't care or don't know.
Public Const FF_ROMAN = 16      '  Variable stroke width, serifed.
Public Const FF_SWISS = 32      '  Variable stroke width, sans-serifed.
Public Const FF_MODERN = 48     '  Constant stroke width, serifed or sans-serifed.
Public Const FF_SCRIPT = 64     '  Cursive, etc.
Public Const FF_DECORATIVE = 80 '  Old English, etc.
' TrueType Flag
Public Const TMPF_TRUETYPE = &H4

例子

VBA:

Sub Example_SetFont()
    ' This example finds the font information for the active text style.
    ' It then changes the font to bold.
    
    Dim typeFace As String
    Dim Bold As Boolean
    Dim Italic As Boolean
    Dim charSet As Long
    Dim PitchandFamily As Long
    
    ThisDrawing.ActiveTextStyle.GetFont typeFace, Bold, Italic, charSet, PitchandFamily
    
    MsgBox "The current text style has the following font properties:" & vbCrLf _
           & "Typeface: " & typeFace & vbCrLf _
           & "Bold: " & Bold & vbCrLf _
           & "Italic: " & Italic & vbCrLf _
           & "Character set: " & charSet & vbCrLf _
           & "Pitch and Family: " & PitchandFamily
            
    ' Change the bold property
    Bold = Not Bold
    
    ThisDrawing.ActiveTextStyle.SetFont typeFace, Bold, Italic, charSet, PitchandFamily
    MsgBox "The current text style has the following font properties:" & vbCrLf _
           & "Typeface: " & typeFace & vbCrLf _
           & "Bold: " & Bold & vbCrLf _
           & "Italic: " & Italic & vbCrLf _
           & "Character set: " & charSet & vbCrLf _
           & "Pitch and Family: " & PitchandFamily
            
    ' Reset the font
    Bold = Not Bold
    ThisDrawing.ActiveTextStyle.SetFont typeFace, Bold, Italic, charSet, PitchandFamily

End Sub

可视化 LISP:

(vl-load-com)
(defun c:Example_SetFont()
    ;; This example finds the font information for the active text style.
    ;; It then changes the font to bold.
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))

    (vla-GetFont (vla-get-ActiveTextStyle doc) 'typeFace 'Bold 'Italic 'charSet 'PitchandFamily)
    
    (alert (strcat "The current text style has the following font properties:"
                   "\nTypeface: " typeFace
                   "\nBold: " (if (= Bold :vlax-true) "True" "False")
                   "\nItalic: " (if (= Italic :vlax-true) "True" "False")
                   "\nCharacter set: " (itoa charSet)
                   "\nPitch and Family: " (itoa PitchandFamily)))
            
    ;; Change the bold property
    (setq Bold (if (= Bold :vlax-true) :vlax-false :vlax-true))

    (vla-SetFont (vla-get-ActiveTextStyle doc) typeFace Bold Italic charSet PitchandFamily)
  
    (alert (strcat "The current text style has the following font properties:"
                   "\nTypeface: " typeFace
                   "\nBold: " (if (= Bold :vlax-true) "True" "False")
                   "\nItalic: " (if (= Italic :vlax-true) "True" "False")
                   "\nCharacter set: " (itoa charSet)
                   "\nPitch and Family: " (itoa PitchandFamily)))
            
    ;; Reset the font
    (setq Bold (if (= Bold :vlax-true) :vlax-false :vlax-true))
    (vla-SetFont (vla-get-ActiveTextStyle doc) typeFace Bold Italic charSet PitchandFamily)
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-6-27 16:12

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部