SetFont 方法 (ActiveX)
设置 TextStyle 字体的定义数据。 支持的平台:仅限 Windows 签名VBA: object.SetFont Typeface, Bold, Italic, CharSet, 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) ) |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-19 07:23
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.