SetFont 方法 (ActiveX)
设置 TextStyle 字体的定义数据。 支持的平台:仅限 Windows 签名VBA: object.SetFont Typeface, Bold, Italic, CharSet, PitchAndFamily
返回值 (RetVal)无返回值。 言论在某些情况下,更改分配给文本样式的字体文件后,字体名称可能无法正确更新。最常见的情况是在打开图形文件期间发生字体替换之后。建议使用对象的属性和方法同时更改字体文件和字体名称(字体)。有关使用字体的详细信息,请参阅《ActiveX 开发人员指南》中的关于分配字体。FontFileSetFontTextStyle 以下部分提供了用于此方法的常量的定义。若要使用这些常量,请复制所需的定义,并将其粘贴到应用程序的“声明”部分。可以在 Visual Basic 开发环境随附的文件win32api.txt中找到 Microsoft 中可用的常量的完整列表。
例子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-3-28 17:06
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.