This project has moved and is read-only. For the latest updates, please go here.
' using events in outlook
' taken from Example06.vb
Public Class Form1

    Public Delegate Sub UpdateEventTextDelegate(ByVal message As String)
    Dim _updateDelegate As UpdateEventTextDelegate

    Public Sub New()

        ' This call is required by the Windows Form Designer.

        _updateDelegate = New UpdateEventTextDelegate(AddressOf UpdateTextbox)

    End Sub

    Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click

        ' start outlook
        Dim outlookApplication As New Outlook.Application()

        ' we register some events. note: the event trigger was called from outlook,
' means an other Thread
Dim mailItem As Outlook.MailItem = _
outlookApplication.CreateItem(OlItemType.olMailItem) Dim closeHandler As Outlook.MailItem_CloseEventHandler = _
AddressOf Me.mailItem_CloseEvent AddHandler mailItem.CloseEvent, closeHandler ' BodyFormat is not available in Outlook 2000 ' we check at runtime is property is available If (mailItem.EntityIsAvailable("BodyFormat")) Then mailItem.BodyFormat = OlBodyFormat.olFormatPlain End If mailItem.Body = "dont type google into google" mailItem.Subject = "Hello there" mailItem.Display() mailItem.Close(OlInspectorClose.olDiscard) ' close word and dispose reference outlookApplication.Quit() outlookApplication.Dispose() End Sub Private Sub mailItem_CloseEvent(ByRef Cancel As Boolean) textBoxEvents.BeginInvoke(_updateDelegate, _
New Object() {"Event Close called."}) End Sub Private Sub UpdateTextbox(ByVal message As String) textBoxEvents.AppendText(message & vbNewLine) End Sub End Class

Last edited Jun 13, 2012 at 12:12 PM by SebastianDotNet, version 7


No comments yet.