CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

SetFont Method (ActiveX)

2023-1-4 02:13| 发布者: admin| 查看: 354| 评论: 0|来自: AutoCAD

摘要: 设置文本样式字体的定义数据。

设置文本样式字体的定义数据。

支持的平台:仅窗口

签名

工 务 局:

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

类型:文本样式

此方法适用的对象。

字体

访问:仅输入

类型:字符串

字体(字体名称)。

大胆

访问:仅输入

类型:布尔

设置为粗体。TextStyle

  • True:泰斯加粗。TextStyle
  • False:不大胆。TextStyle
斜体的

访问:仅输入

类型:布尔

设置为斜体。TextStyle

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

访问:仅输入

类型:

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

音调与家庭

访问:仅输入

类型:

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

返回值(RetVal)

无返回值。

言论

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

字符集参数指定字体的字符集。若要在 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值,请从每个类别中选择一个设置,然后使用 OR 运算符将它们组合在一起。前两个类别中需要设置;球场和家庭。第三个类别是 TrueType 标志,仅在指定 TrueType 字体时使用。

To use the following constants in your VB or VBA application, copy the definitions into the Declaration section of your code.

' 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

Examples

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

Visual 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-5-12 07:55

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部