CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

相关分类

添加工具栏按钮方法 (ActiveX)

2023-1-4 12:08| 发布者: admin| 查看: 567| 评论: 0|来自: AutoCAD

摘要: 将工具栏项添加到工具栏的指定位置。

将工具栏项添加到工具栏的指定位置。

支持的平台:仅窗口

签名

工 务 局:

RetVal = object.AddToolbarButton(Index, Name, HelpString, Macro [, FlyoutButton])
对象

类型:工具栏

此方法适用的对象。

指数

访问:仅输入

类型:变体

工具栏中要添加项的索引位置。

索引必须是整数或字符串。如果指定整数,则索引必须介于 0 和N-1 之间,其中N是工具栏中的对象数。新项将紧接在指定的索引位置之前添加。

名字

访问:仅输入

类型:字符串

标识工具栏按钮的字符串。字符串必须包含字母数字字符,除短划线 (-) 或下划线 (_) 外没有标点符号。当光标放在工具栏按钮上时,此字符串将显示为工具提示。

帮助字符串

访问:仅输入

类型:字符串

显示在按钮的 AutoCAD 状态行中的字符串。

宏观

访问:仅输入

类型:字符串

与此项关联的宏的名称。

浮出控件按钮

访问:仅输入;自选

类型:变体

一个布尔变量,指示新按钮是否为浮出控件按钮。如果按钮是浮出控件按钮,则必须将此参数设置为 。如果按钮不是浮出控件按钮,则可以将此参数设置为或忽略,并将返回 newobject。TrueFalseToolbarItem

  • True:该按钮是一个浮出控件按钮。
  • False:按钮不是浮出控件按钮。

返回值(RetVal)

类型:工具栏项

新创建的工具栏项。

言论

您只能在工具栏可见时添加或删除工具栏按钮。

例子

工 务 局:

Sub Example_AddToolbarButton()
    ' This example creates a new toolbar called TestToolbar and inserts a
    ' toolbar button into it. The toolbar is then displayed.
    ' To remove the toolbar after execution of this macro, use the Customize Menu
    ' option from the Tools menu.
    
    Dim currMenuGroup As acadMenuGroup
    Set currMenuGroup = ThisDrawing.Application.MenuGroups.Item(0)
    
    ' Create the new toolbar
    Dim newToolBar As AcadToolbar
    Set newToolBar = currMenuGroup.Toolbars.Add("TestToolbar")
    
    ' Add a button to the new toolbar
    Dim newButton As AcadToolbarItem
    Dim openMacro As String
    
    ' Assign the macro string the VB equivalent of "ESC ESC _open "
    openMacro = Chr(3) & Chr(3) & Chr(95) & "open" & Chr(32)
    
    Set newButton = newToolBar.AddToolbarButton("", "NewButton", "Open a file.", openMacro)
    
    ' Display the toolbar
    newToolBar.Visible = True
    
End Sub

Visual LISP:

(vl-load-com)
(defun c:Example_AddToolbarButton()
    ;; This example creates a new toolbar called TestToolbar and inserts a
    ;; toolbar button into it. The toolbar is then displayed.
    ;; To remove the toolbar after execution of this macro, use the Customize Menu
    ;; option from the Tools menu.
    (setq acadObj (vlax-get-acad-object))
    (setq currMenuGroup (vla-Item (vla-get-MenuGroups acadObj) 0))
    
    ;; Create the new toolbar
    (setq newToolBar (vla-Add (vla-get-Toolbars currMenuGroup) "TestToolbar"))
    
    ;; Assign the macro string the VB equivalent of "ESC ESC _open "
    (setq openMacro (strcat (Chr 3) (Chr 3) (Chr 95) "open" (Chr 32)))
    (setq newButton (vla-AddToolbarButton newToolBar "" "NewButton" "Open a file." openMacro))
    
    ;; Display the toolbar
    (vla-put-Visible newToolBar :vlax-true)
)

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-11 18:58

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部