Before you can respond to an event, the event must be registered with AutoCAD. You register an event by creating a new event handler of the desired type and then assigning it to the object in which you want to register the event with. Once you are done with an event, it is best to unregister the event to minimize conflicts with other reactors as well as reduce the about of memory and CPU usage that AutoCAD requires to maintain your event handler.
用记在可以响应事件前,事件必须在 AutoCAD 中注册。通过创建一个新的合适的类型的事件处理程序注册事件,然后将它指定给你想注册的事件的对象。一旦事件完成,最好是注册它,以尽量减小和其它反应器的冲突以及减少 AutoCAD 需要维护事务处理程序所使用的内存和 CPU 时间。
You register an event by appending an event handler to an event. The event handler object requires a procedure that you must have defined in your project. Most event handlers require a procedure that accepts two paramters, one of the type Object and another that represents the return arguments of the event. You register an event by using the VB.NET AddHandler statement or the C# += operator.
用户通过为事件追加一个事件处理程序来注册。事件处理程序对象需要一个必须在用户工程中定义的过程。大多数事件处理程序需要一个接受两个参数的过程,一个参数的类型为 Object 而另一个表示事件的返回参数。注册事件使用 VB.NET 的 AddHandler 语句或 C# 的 += 运算符。
The following code registers a procedure named appSysVarChanged with an object type of SystemVariableChangedEventHandler to the SystemVariableChanged event. The appSysVarChanged procedure accepts two paramters: Object and SystemVariableChangedEventArgs. The SystemVariableChangedEventArgs object returns the name of the system variabled changed when the event is registered.
下面代码注册一个名为 appSysVarChanged 的过程与 SystemVariableChangedEventHandler 对象类型的 SystemVariableChanged 事件相关联。appSysVarChanged 过程接受两个参数: Object 和 SystemVariableChangedEventArgs。SystemVariableChangedEventArgs 对象返回事件被注册后修改的系统变量的名字。
An event is unregistered by removing an event handler from the event in which it is assigned. You use the same syntax in which was used to register the event handler with an event with the exception you use RemoveHandler or the -= operator.
事件的解除注册是通过从事件中移除分配给它的事件处理程序来完成的。用户利用与注册事件处理程序与事件相同的语法,??????????????
The following code unregisters a procedure named appSysVarChanged with an object type of SystemVariableChangedEventHandler from the SystemVariableChanged event.
下面代码从对象类型为 SystemVariableChangedEventHandler 的 SystemVariableChanged 事件中解除注册名为 appSysVarChanged 的过程。