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 对象:
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 事件指示一个图形窗口已激活。当事件出现时将显示一个消息框,内容为被激活文档的图形名。
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
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.");
}