Application object events are are used to respond to the application window. Once an Application event is registered, it remains registered until AutoCAD is shutdown or the event is unregistered.

应用程序对象事件用于响应应用程序窗口。一旦应用程序事件被注册,它就一直会存在,直到 AutoCAD 被关闭或事件解除注册。

The following events are available for the Application object:

下面的事件可用于应用程序对象:

BeginCustomizationMode

Triggered just before AutoCAD enters customization mode.

仅在 AutoCAD 进入自定义模式时触发。

BeginDoubleClick

Triggered when the mouse button is double clicked.

当鼠标双击时触发。

BeginQuit

Triggered just before an AutoCAD session ends.

仅在 AutoCAD 进程结束前触发。

DisplayingCustomizeDialog

Triggered just before the Customize dialog box is displayed.

仅在自定义对话框显示前触发。

DisplayingDraftingSettingsDialog

Triggered just before the Drafting Settings dialog box is displayed.

仅在草图设置对话框显示前触发。

DisplayingOptionDialog

Triggered just before the Options dialog box is displayed.

仅在选项对话框显示前触发。

EndCustomizationMode

Triggered when AutoCAD exits customization mode.

当 AutoCAD 退出自定义模式时触发。

EnterModal

Triggered just before a modal dialog box is displayed.

仅在模型对话框显示前触发。

Idle

Triggered when AutoCAD text.

当 AutoCAD 发送信息时触发。

LeaveModal

Triggered when a modal dialog box is closed.

当模型对话框关闭时触发。

PreTranslateMessage

Triggered just before a message is translated by AutoCAD.

仅在通过 AutoCAD 转换一个信息时触发。

QuitAborted

Triggered when an attempt to shutdown AutoCAD is aborted.

当尝试终止正在关闭的 AutoCAD 时触发。

QuitWillStart

Triggered after the BeginQuit event and before shutdown begins.

在 BeginQuit 事件后,开始关闭前触发。

SystemVariableChanged

Triggered when an attempt to change a system variable is made.

当尝试修改系统变量完成时触发。

SystemVariableChanging

Triggered just before an attempt is made at changing a system variable.

仅在尝试修改系统变量前触发。

启用应用程序对象事件

This example demonstrates how to register an event handler with the BeginQuit event. Once registered, a message box is displayed before AutoCAD completely shutdown.

本例演示如何用 BeginQuit 事件注册事件处理程序。一旦注册完,AutoCAD 完全关闭前会显示一个对话框。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
 
<CommandMethod("AddAppEvent")> _
Public Sub AddAppEvent()
  AddHandler Application.SystemVariableChanged, AddressOf appSysVarChanged
End Sub
 
<CommandMethod("RemoveAppEvent")> _
Public Sub RemoveAppEvent()
  RemoveHandler Application.SystemVariableChanged, AddressOf appSysVarChanged
End Sub
 
Public Sub appSysVarChanged(ByVal senderObj As Object, _
                            ByVal sysVarChEvtArgs As Autodesk.AutoCAD.ApplicationServices. _
                            SystemVariableChangedEventArgs)
 
  Dim oVal As Object = Application.GetSystemVariable(sysVarChEvtArgs.Name)
 
  '' 显示一个拥有系统变量名和新值的消息框   Display a message box with the system variable name and the new value
  Application.ShowAlertDialog(sysVarChEvtArgs.Name & " was changed." & _
                              vbLf & "New value: " & oVal.ToString())
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
[CommandMethod("AddAppEvent")]
public void AddAppEvent()
{
  Application.SystemVariableChanged +=
      new Autodesk.AutoCAD.ApplicationServices.
          SystemVariableChangedEventHandler(appSysVarChanged);
}
 
[CommandMethod("RemoveAppEvent")]
public void RemoveAppEvent()
{
  Application.SystemVariableChanged -=
      new Autodesk.AutoCAD.ApplicationServices.
          SystemVariableChangedEventHandler(appSysVarChanged);
}
 
public void appSysVarChanged(object senderObj, 
                             Autodesk.AutoCAD.ApplicationServices.
                             SystemVariableChangedEventArgs sysVarChEvtArgs)
{
  object oVal = Application.GetSystemVariable(sysVarChEvtArgs.Name);
 
  // 显示一个拥有系统变量名和新值的消息框   Display a message box with the system variable name and the new value
  Application.ShowAlertDialog(sysVarChEvtArgs.Name + " was changed." +
                              "\nNew value: " + oVal.ToString());
}
VBA/ActiveX 代码参考