在使用对象级事件之前,必须创建一个新的类模块,并使用事件声明一个类型的对象。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 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:48
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.