处理应用程序事件 (.NET)
应用程序对象事件用于响应应用程序窗口。注册应用程序事件后,它将保持注册状态,直到 AutoCAD 关闭或取消注册该事件。 以下事件可用于 Application 对象:
启用 Application 对象事件此示例演示如何向 BeginQuit 事件注册事件处理程序。注册后,在AutoCAD完全关闭之前会显示一个消息框。 VB.NETImports 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 代码参考Public WithEvents ACADApp As AcadApplication
Sub Example_AcadApplication_Events()
' Intialize the public variable (ACADApp)
'
' Run this procedure first
Set ACADApp = ThisDrawing.Application
End Sub
Private Sub ACADApp_SysVarChanged(ByVal SysvarName As String, _
ByVal newVal As Variant)
' This procedure intercepts an Application SysVarChanged event.
MsgBox (SysvarName & " was changed." & _
vbLf & "New value: " & newVal)
End Sub
相关概念父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-10-24 20:09
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.