CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

处理文档事件 (.NET)

2023-1-1 09:05| 发布者: admin| 查看: 411| 评论: 0|来自: AutoCAD

Document对象事件用于响应文档窗口。注册文档事件时,它仅与关联该事件的文档对象相关联。因此,如果需要向每个文档注册事件,则需要使用对象的事件将事件注册到每个新的或打开的图形中。DocumentCreatedDocumentCollection

以下事件可用于对象:Document

开始文档关闭

在收到关闭图形的请求后触发。

开始DwgOpen

在图形即将打开时触发。

关闭已中止

在尝试关闭图形时中止时触发。

关闭将开始

在 BeginDocumentClose 事件之后和关闭图形开始之前触发。

命令已取消

在命令完成之前取消命令时触发。

命令已结束

命令完成后立即触发。

命令失败

当命令无法完成且未取消时触发。

命令将启动

在发出命令后立即触发,但在命令完成之前触发。

EndDwgOpen

打开图形时触发。

隐含选择已更改

在当前选择优先选择集更改时触发。

布局切换

在布局设置为当前布局后触发。

布局切换

在布局设置为当前后触发。

Lisp已取消

在取消对 LISP 表达式的计算时触发。

LispEnd

在完成计算 LISP 表达式时触发。

LispWillStart

在 AutoCAD 收到求值 LISP 表达式的请求后立即触发。

未知命令

在命令提示符下输入未知命令时立即触发。

视图已更改

在图形视图更改后触发。

启用文档对象事件

下面的示例使用 event 提示用户是否要继续关闭当前图形。将显示一个消息框,其中包含“是”和“否”按钮。单击“否”将使用事件处理程序返回的参数的方法中止绘图的关闭。BeginDocumentCloseVeto

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
 
<CommandMethod("AddDocEvent")> _
Public Sub AddDocEvent()
  '' Get the current document
  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
 
  AddHandler acDoc.BeginDocumentClose, AddressOf docBeginDocClose
End Sub
 
<CommandMethod("RemoveDocEvent")> _
Public Sub RemoveDocEvent()
  '' Get the current document
  Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
 
  RemoveHandler acDoc.BeginDocumentClose, AddressOf docBeginDocClose
End Sub
 
Public Sub docBeginDocClose(ByVal senderObj As Object, _
                            ByVal docBegClsEvtArgs As DocumentBeginCloseEventArgs)
 
  '' Display a message box prompting to continue closing the document
  If System.Windows.Forms.MessageBox.Show( _
                      "The document is about to be closed." & _
                      vbLf & "Do you want to continue?", _
                      "Close Document", _
                      System.Windows.Forms.MessageBoxButtons.YesNo) = _
                      System.Windows.Forms.DialogResult.No Then
      docBegClsEvtArgs.Veto()
  End If
End If

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
 
[CommandMethod("AddDocEvent")]
public void AddDocEvent()
{
  // Get the current document
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
 
  acDoc.BeginDocumentClose += 
      new DocumentBeginCloseEventHandler(docBeginDocClose);
}
 
[CommandMethod("RemoveDocEvent")]
public void RemoveDocEvent()
{
  // Get the current document
  Document acDoc = Application.DocumentManager.MdiActiveDocument;
 
  acDoc.BeginDocumentClose -=
      new DocumentBeginCloseEventHandler(docBeginDocClose);
}
 
public void docBeginDocClose(object senderObj, 
                             DocumentBeginCloseEventArgs docBegClsEvtArgs)
{
  // Display a message box prompting to continue closing the document
  if (System.Windows.Forms.MessageBox.Show(
                       "The document is about to be closed." +
                       "\nDo you want to continue?",
                       "Close Document",
                       System.Windows.Forms.MessageBoxButtons.YesNo) ==
                       System.Windows.Forms.DialogResult.No)
  {
      docBegClsEvtArgs.Veto();
  }
}

VBA/ActiveX 代码参考

Private Sub AcadDocument_BeginDocClose(Cancel As Boolean)
    ' This procedure intercepts the Document BeginDocClose event.
 
    If MsgBox("The document is about to be closed." & _
              vbLf & "Do you want to continue?", vbYesNo, _
              "Close Document") = vbNo Then
 
           ' Veto the document close
           Cancel = True
    End If
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 14:29

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部