处理文档事件 (.NET)
Document对象事件用于响应文档窗口。注册文档事件时,它仅与与其关联的文档对象相关联。因此,如果需要将事件注册到每个文档中,则需要使用对象的事件来注册每个新图形或打开的图形的事件。DocumentCreatedDocumentCollection 以下事件可用于对象:Document
启用 Document 对象事件下面的示例使用该事件提示用户是否要继续关闭当前图形。将显示一个消息框,其中包含“是”和“否”按钮。单击“否”将使用事件处理程序返回的参数的方法中止图形的关闭。BeginDocumentCloseVeto VB.NETImports 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 相关概念父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2024-12-15 22:10
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.