处理 DocumentCollection 事件
 
 

DocumentCollection object events are used to respond to the open documents in the application. DocumentCollection events, unlike Document object events, remain registered until AutoCAD is shutdown or until they are unregistered.

DocumentCollection 对象事件用于响应在应用程序中打开文档。DocumentCollection 事件不同于 Document 对象事件,它将一直保持注册状态,直到 AutoCAD 关闭或 解除注册。

The following events are available for DocumentCollection objects:

下面的事件可用于 DocumentCollection 对象:

DocumentActivated

Triggered when a document window is activated.

当文档窗口激活时触发。

DocumentActivationChanged

Triggered after the active document window is deactivated or destroyed.

活动文档窗口失活或销毁后触发。

DocumentBecameCurrent

Triggered when a document window is set current and is different from the previous active document window.

当文档窗口设置为当前文档并且与前一个活动文档窗口不同时触发。

DocumentCreated

Triggered after a document window is created. Occurs after a new drawing is created or an existing drawing is opened.

文档窗口被创建后触发。创建一个新图形或打开一个现有图形后出现。

DocumentCreateStarted

Triggered just before a document window is created. Occurs before a new drawing is created or an existing drawing is opened.

仅在文档窗口被创建前触发。创建一个新图形或打开一个现有图形前出现。

DocumentCreationCanceled

Triggered when a request to create a new drawing or to open an existing drawing is cancelled.

当要求创建新图形以及打开一个现有图形被取消后触发。

DocumentDestroyed

Triggered before a document window is destroyed and its associated database object is deleted.

在文档窗口被销毁以及与它关联的数据库对象被删除前触发。

DocumentLockModeChanged

Triggered after the lock mode of a document has changed.

文档的锁定模式被修改后触发。

DocumentLockModeChangeVetoed

Triggered after the lock mode change is vetoed.

修改文档的锁定模式被禁止后触发。

DocumentLockModeWillChange

Triggered before the lock mode of a document is changed.

文档的锁定模式被修改前触发。

DocumentToBeActivated

Triggered when a document is about to be activated.

当文档将要被激活时触发。

DocumentToBeDeactivated

Triggered when a document is about to be deactivated.

当文档将要失活时触发。

DocumentToBeDestroyed

Triggered when a document is about to be destroyed.

当文档将要销毁时触发。

启用 DocumentCollection 对象事件

The following example uses the DocumentActivated event to indicate when a drawing window has been activated. A message box with the name of the drawing that is activated is displayed when the event occurs.

下面示例使用 DocumentActivated 事件指示一个图形窗口已激活。当事件出现时将显示一个消息框,内容为被激活文档的图形名。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
 
<CommandMethod("AddDocColEvent")> _
Public Sub AddDocColEvent()
  AddHandler Application.DocumentManager.DocumentActivated, _
      AddressOf docColDocAct
End Sub
 
<CommandMethod("RemoveDocColEvent")> _
Public Sub RemoveDocColEvent()
  RemoveHandler Application.DocumentManager.DocumentActivated, _
      AddressOf docColDocAct
End Sub
 
Public Sub docColDocAct(ByVal senderObj As Object, _
                        ByVal docColDocActEvtArgs As DocumentCollectionEventArgs)
  Application.ShowAlertDialog(docColDocActEvtArgs.Document.Name & _
                              " was activated.")
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
 
[CommandMethod("AddDocColEvent")]
public void AddDocColEvent()
{
  Application.DocumentManager.DocumentActivated +=
      new DocumentCollectionEventHandler(docColDocAct);
}
 
[CommandMethod("RemoveDocColEvent")]
public void RemoveDocColEvent()
{
  Application.DocumentManager.DocumentActivated -=
      new DocumentCollectionEventHandler(docColDocAct);
}
 
public void docColDocAct(object senderObj, 
                         DocumentCollectionEventArgs docColDocActEvtArgs)
{
  Application.ShowAlertDialog(docColDocActEvtArgs.Document.Name +
                              " was activated.");
}
VBA/ActiveX 代码参考