Solid Edge Framework Type Library
ApplicationEvents Property
Solid Edge Framework Type Library > Application Object : ApplicationEvents Property
Description
Returns the ApplicationEvents object for the referenced Application object.
Property type
Read-only property
Syntax
Visual Basic
Public Property ApplicationEvents As ApplicationEvents
Example
Imports System
Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Namespace Examples
    Partial Public Class Form1
        Inherits Form

        Private _application As SolidEdgeFramework.Application
        Private _applicationEvents As SolidEdgeFramework.ISEApplicationEvents_Event

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
            ' Connect to a running instance of Solid Edge.
            _application = DirectCast(Marshal.GetActiveObject("SolidEdge.Application"), SolidEdgeFramework.Application)

            ' Connect to application events using delegate event model.
            _applicationEvents = CType(_application.ApplicationEvents, SolidEdgeFramework.ISEApplicationEvents_Event)

            ' Attach to specific events.
            AddHandler _applicationEvents.AfterDocumentSave, AddressOf _applicationEvents_AfterDocumentSave
            AddHandler _applicationEvents.BeforeDocumentSave, AddressOf _applicationEvents_BeforeDocumentSave
        End Sub

        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs)
            If _applicationEvents IsNot Nothing Then
                ' Dettach from specific events.
                RemoveHandler _applicationEvents.AfterDocumentSave, AddressOf _applicationEvents_AfterDocumentSave
                RemoveHandler _applicationEvents.BeforeDocumentSave, AddressOf _applicationEvents_BeforeDocumentSave
            End If

            _applicationEvents = Nothing
            _application = Nothing
        End Sub

        Private Sub _applicationEvents_BeforeDocumentSave(ByVal theDocument As Object)
            ' Handle AfterDocumentSave.
        End Sub

        Private Sub _applicationEvents_AfterDocumentSave(ByVal theDocument As Object)
            ' Handle BeforeDocumentSave.
        End Sub
    End Class
End Namespace
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace Examples
{
    public partial class Form1 : Form
    {
        private SolidEdgeFramework.Application _application;
        private SolidEdgeFramework.ISEApplicationEvents_Event _applicationEvents;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // Connect to a running instance of Solid Edge.
            _application = (SolidEdgeFramework.Application)Marshal.GetActiveObject("SolidEdge.Application");

            // Connect to application events using delegate event model.
            _applicationEvents = (SolidEdgeFramework.ISEApplicationEvents_Event)_application.ApplicationEvents;

            // Attach to specific events.
            _applicationEvents.AfterDocumentSave += _applicationEvents_AfterDocumentSave;
            _applicationEvents.BeforeDocumentSave += _applicationEvents_BeforeDocumentSave;
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (_applicationEvents != null)
            {
                // Dettach from specific events.
                _applicationEvents.AfterDocumentSave -= _applicationEvents_AfterDocumentSave;
                _applicationEvents.BeforeDocumentSave -= _applicationEvents_BeforeDocumentSave;
            }

            _applicationEvents = null;
            _application = null;
        }

        private void _applicationEvents_BeforeDocumentSave(object theDocument)
        {
            // Handle AfterDocumentSave.
        }

        private void _applicationEvents_AfterDocumentSave(object theDocument)
        {
            // Handle BeforeDocumentSave.
        }
    }
}
See Also

Application Object  | Application Members