在使用对象级事件之前,必须创建一个新的类模块并声明一个 typewith 事件的对象。AcadObject 例如,假定创建了一个新的类模块并称为 EventClassModule。新的类模块包含带有 VBA 关键字的应用程序声明。WithEvents 每当更新折线时,显示闭合折线的区域本示例创建一条包含事件的轻量级折线。然后,每当更改折线时,折线的事件处理程序都会显示新区域。要触发事件,只需在AutoCAD中更改折线的大小。请记住,必须在激活事件处理程序之前运行子例程。CreatePLineWithEvents Public WithEvents PLine As AcadLWPolyline Sub CreatePLineWithEvents() ' This example creates a light weight polyline Dim points(0 To 9) As Double points(0) = 1: points(1) = 1 points(2) = 1: points(3) = 2 points(4) = 2: points(5) = 2 points(6) = 3: points(7) = 3 points(8) = 3: points(9) = 2 Set PLine = ThisDrawing.ModelSpace. _ AddLightWeightPolyline(points) PLine.Closed = True ThisDrawing.Application.ZoomAll End Sub Private Sub PLine_Modified _ (ByVal pObject As AutoCAD.IAcadObject) ' This event is triggered when the polyline is resized. ' If the polyline is deleted the modified event is still ' triggered, so we use the error handler to avoid ' reading data from a deleted object. On Error GoTo ERRORHANDLER MsgBox "The area of " & pObject.ObjectName & " is: " _ & pObject.Area Exit Sub ERRORHANDLER: MsgBox Err.Description End Sub |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )
GMT+8, 2024-6-10 18:36
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.