sharksun 发表于 2004-7-10 23:14:00

[求助]关于事件的使用

Public WithEvents PLine As AcadLWPolyline<BR>Sub CreatePLineWithEvents()<BR>                       ' 本例创建一细多义线<BR>                       Dim points(0 To 9) As Double<BR>                       points(0) = 1: points(1) = 1<BR>                       points(2) = 1: points(3) = 2<BR>                       points(4) = 2: points(5) = 2<BR>                       points(6) = 3: points(7) = 3<BR>                       points(8) = 3: points(9) = 2<BR>                       Set PLine = ThisDrawing.ModelSpace.AddLightWeightPolyline(points)<BR>                       PLine.Closed = True<BR>                       Dim pt1(0 To 5) As Double<BR>                       Dim pt2(0 To 2) As Double<BR>                       pt1(0) = 0: pt1(1) = 0: pt1(2) = 2<BR>                       pt1(3) = 2: pt1(4) = 4: pt1(5) = 5<BR>                       Set PLine = ThisDrawing.ModelSpace.AddLightWeightPolyline(pt1)<BR>                       PLine.Closed = True


                       ThisDrawing.Application.ZoomAll<BR>End Sub


Private Sub PLine_Modified _<BR>                                                                                                               (ByVal pObject As AutoCAD.IAcadObject)<BR><BR>                       On Error GoTo ERRORHANDLER<BR>                       MsgBox "对象" &amp; pObject.ObjectName &amp; " 的面积为: " _<BR>                                                                                       &amp; pObject.Area<BR>                       Exit Sub<BR>                       <BR>ERRORHANDLER:<BR>                       MsgBox Err.Description<BR>End Sub<BR>


以上的代码,顺利执行后,只有在图形中改动后来创建的PLine对象,才触发事件。但是改变前一个PLine对象,并不触发。我的要求是创建多个PLine对象,(我试了一下,用数组PLine(0),PLine(1)不行)如何改变任何一个对象,都触发对象改动事件么?


谢谢指教。

shenhui 发表于 2004-7-11 03:49:00

这样行不通的,应该启用文档层次的事件AcadDocument_ObjectModified监视所有的图元修改
页: [1]
查看完整版本: [求助]关于事件的使用