S
Steffen Grellmann
Hi newsgroup,
I'm trying to add a custom button to a new inspectors commandbar in
Outlook 2003. Word is used as e-mail editor. Everything is working
fine so far.
But what would be the correct technique to add a handler to my custom
button? If I add the handler like shown in the code below, with every
new inspector that is opened a new handler is added to my button. This
lets the click procedure fire that many times inspectors has been
opened so far. Would it be a solution to initialize a Boolean variable
to check if the handler has been added or which is the preferred way
to add the button handler in this constellation?
Any help is highly appreciated.
Kind regards,
Steffen
Public Class ThisAddIn
Dim MyButton As Office.CommandBarButton
Dim selectInspectors As Outlook.Inspectors
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
selectInspectors = Application.Inspectors()
AddHandler selectInspectors.NewInspector, AddressOf
NewInspector_Event
End Sub
Private Sub NewInspector_Event(ByVal new_Inspector As
Outlook.Inspector)
If
new_Inspector.CurrentItem.MessageClass.ToUpper.Contains("IPM.NOTE")
Then
Try 'inserting Button
MyButton = new_Inspector.CommandBars.FindControl(, ,
"MyTag")
If MyButton Is Nothing Then 'only if doesn't exist
MyButton =
new_Inspector.CommandBars.Item("E-mail").Controls.Add(1, , , , False)
With MyButton
.Style =
Office.MsoButtonStyle.msoButtonIconAndCaption
.Caption = "MyCaption"
.Tag = "MyTag"
.TooltipText = "MyTooltipp"
.FaceId = 1100
End With
AddHandler MyButton.Click, AddressOf ButtonClick
Else
AddHandler MyButton.Click, AddressOf ButtonClick
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
Private Sub ButtonClick(ByVal ctrl As Office.CommandBarButton,
ByRef Cancel As Boolean)
MessageBox.Show("You clicked: " + ctrl.Caption)
End Sub
End Class
I'm trying to add a custom button to a new inspectors commandbar in
Outlook 2003. Word is used as e-mail editor. Everything is working
fine so far.
But what would be the correct technique to add a handler to my custom
button? If I add the handler like shown in the code below, with every
new inspector that is opened a new handler is added to my button. This
lets the click procedure fire that many times inspectors has been
opened so far. Would it be a solution to initialize a Boolean variable
to check if the handler has been added or which is the preferred way
to add the button handler in this constellation?
Any help is highly appreciated.
Kind regards,
Steffen
Public Class ThisAddIn
Dim MyButton As Office.CommandBarButton
Dim selectInspectors As Outlook.Inspectors
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Startup
selectInspectors = Application.Inspectors()
AddHandler selectInspectors.NewInspector, AddressOf
NewInspector_Event
End Sub
Private Sub NewInspector_Event(ByVal new_Inspector As
Outlook.Inspector)
If
new_Inspector.CurrentItem.MessageClass.ToUpper.Contains("IPM.NOTE")
Then
Try 'inserting Button
MyButton = new_Inspector.CommandBars.FindControl(, ,
"MyTag")
If MyButton Is Nothing Then 'only if doesn't exist
MyButton =
new_Inspector.CommandBars.Item("E-mail").Controls.Add(1, , , , False)
With MyButton
.Style =
Office.MsoButtonStyle.msoButtonIconAndCaption
.Caption = "MyCaption"
.Tag = "MyTag"
.TooltipText = "MyTooltipp"
.FaceId = 1100
End With
AddHandler MyButton.Click, AddressOf ButtonClick
Else
AddHandler MyButton.Click, AddressOf ButtonClick
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
Private Sub ButtonClick(ByVal ctrl As Office.CommandBarButton,
ByRef Cancel As Boolean)
MessageBox.Show("You clicked: " + ctrl.Caption)
End Sub
End Class