该样例程序是通过执行“AddEvent”命后,进行注册ObjectErased事件。在注册了该事件之后,每当删除对象时,就是激活该事件进行调用自定义的ObjectErasedEvent函数。
但是如果运行RemoveEvent命令后,将会注销该命令。在注册了该命令后,即使是删除对象,也不会激活事件的。即也不会调用自定义函数。
Imports ZwSoft.ZwCAD.Runtime
Imports ZwSoft.ZwCAD.DatabaseServicesImports ZwSoft.ZwCAD.ApplicationServices
Namespace ZwApp
Public Class EventSample
<CommandMethod("AddEvent")> _
Public Sub AddObjectErasedEvent()
Dim ZcDB As Database = HostApplicationServices.WorkingDatabase
AddHandler ZcDB.ObjectErased, AddressOf ObjectErasedEvent
End Sub
<CommandMethod("RemoveEvent")> _
Public Sub RemoveObjectErasedEvent()
Dim ZcDB As Database = HostApplicationServices.WorkingDatabase
AddHandler ZcDB.ObjectErased, AddressOf ObjectErasedEvent
End Sub
Public Shared Sub ObjectErasedEvent(ByVal sender As Object, ByVal e As ObjectErasedEventArgs)
Application.ShowAlertDialog(vbLf & "Object(s) erased")
End Sub
End Class
End Namespace