CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

关于启用应用程序级事件 (VBA/ActiveX)

2023-1-4 21:38| 发布者: admin| 查看: 561| 评论: 0|来自: AutoCAD

摘要: 在使用应用程序级事件之前,必须创建一个新的类模块并声明一个类型的对象 带有事件的 AcadApplication 。

在使用应用程序级事件之前,必须创建一个新的类模块并声明一个 typewith 事件的对象。AcadApplication

例如,假定创建了一个新的类模块并称为 EventClassModule。新的类模块包含带有 VBA 关键字的应用程序声明。WithEvents

将图形拖放到 AutoCAD 中时提示继续

本示例截获将文件拖放到 AutoCAD 中的加载过程。一个消息框,其中包含已删除文件的名称和“是/否/继续”按钮,允许用户决定是否应继续加载或显示文件。如果用户选择取消操作,则通过事件的Cancel参数返回该决策,并且不会加载文件。BeginFileDrop

Public WithEvents ACADApp As AcadApplication

Sub Example_AcadApplication_Events()
 ' This example intializes the public variable (ACADApp)
 ' which will be used to intercept AcadApplication Events
 '
 ' Run this procedure FIRST!

 ' We could get the application from the ThisDocument
 ' object, but that would require having a drawing open,
 ' so we grab it from the system.
 Set ACADApp = GetObject(, "AutoCAD.Application.24")
End Sub

Private Sub ACADApp_BeginFileDrop _
 (ByVal FileName As String, Cancel As Boolean)
 ' This example intercepts an Application BeginFileDrop event.
 '
 ' This event is triggered when a drawing file is dragged
 ' into AutoCAD.
 '
 ' To trigger this example event:
 '     1) Make sure to run the example that initializes
 '     the public variable (named ACADApp) linked to this event.
 '
 '     2) Drag an AutoCAD drawing file into the AutoCAD
 '        application from either the Windows Desktop
 '        or Windows Explorer

 ' Use the "Cancel" variable to stop the loading of the
 ' dragged file, and the "FileName" variable to  notify
 ' the user which file is about to be dragged in.

 If MsgBox("AutoCAD is about to load " & FileName & vbCrLf _
 & "Do you want to continue loading this file?", _
 vbYesNoCancel + vbQuestion) <> vbYes Then
 Cancel = True
 End If
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部