Now you can add the code in Listing to the Ribbon Callbacks region to create event handlers for the Toggle Button controls These methods match the OnAction values you added to the Ribbon XML files

Listing 14.21. Adding the ToggleButton handlers

Public Sub ReadMailRibbonOnToggleButton1( _ ByVal control As Office.IRibbonControl, _ ByVal isPressed As Boolean)

If (isPressed) Then

MessageBox.Show("Pressed!")

Else

MessageBox.Show("Released!") End If

End Sub

Public Sub ContactRibbonOnToggleButton1( _

ByVal control As Office.IRibbonControl, _ ByVal isPressed As Boolean)

If (isPressed) Then

MessageBox.Show("Pressed!")

Else

MessageBox.Show("Released!") End If

End Sub

Next, you'll create a generic event handler called OnToggleButton. This handler is called by both ReadMailToggleButton2 and ContactToggleButton2. Even though it is a general handler, you can create specific logic based on the control ID. The logic is the same when the toggleButton is released; however, when the toggleButton is pressed, the results differ depending on the control ID. Add the code in Listing 14.22 to the Ribbon Callbacks region to create event handlers for the other toggleButton controls.

Listing 14.22. Adding the generic OnToggleButton event handler

Public Sub OnToggleButton(ByVal control As _

Office.IRibbonControl, ByVal isPressed As Boolean)

If (isPressed) Then

If control.Id = "ContactRibbon.toggleButton2" Then MessageBox.Show("Contact Toggle Pressed")

Else

MessageBox.Show("Pressed!") End If

Else

MessageBox.Show("Released!") End If

End Sub

Finally, uncomment the partial class that handles the service request at the top of the code file, and press F5 to run the code. When you open an existing e-mail, you'll see that the Ribbon contains the ReadMailRibbon Group in the ReadMailRibbon tab, which has two toggle buttons, as shown in Figure 14.32.

HeitSffilEen'- Message (HTML) - a x

ReadMailRibbon Group

From: pstubbs-u2

To: kmcgrath-ul

Subject: Hey Kathleen

From: pstubbs-u2

To: kmcgrath-ul

Subject: Hey Kathleen

Outlook is cool

< \ IUI 1 ► 1

Figure 14.32. The ReadMailRibbon tab on an e-mail Inspector

Figure 14.32. The ReadMailRibbon tab on an e-mail Inspector

ReadMailRibbon Group

If you click either button, a message box displays "Pressed!" and, when clicked again, displays "Released!" Notice also that this Ribbon appears only when you read an existing mail item, not when you create a new one.

When you open a contact item, the ContactRibbon tab appears, as illustrated in Figure 14.33. This time the behavior of each of the toggle buttons differs. When you click ContactRibbon ToggleButton 1, the generic "Pressed!" message is displayed; however, when you click ContactRibbon ToggleButton 2, the message box displays "Contact Toggle Pressed." The control ID passed to the OnToggleButton method determines which message is displayed.

Figure 14.33. The ContactRibbon tab on a mail Inspector

Following are all the valid ribbonID values available for Outlook Inspector items.

• Microsoft.Outlook.Mail.Read

• Microsoft.Outlook.Mail.Compose

• Microsoft.Outlook.MeetingRequest.Read

• Microsoft.Outlook.MeetingRequest.Send

• Microsoft.Outlook.Appointment

• Microsoft.Outlook.Contact

• Microsoft.Outlook.Journal

• Microsoft.Outlook.Task

• Microsoft.Outlook.DistributionList

• Microsoft.Outlook.Report

• Microsoft.Outlook.Resend

• Microsoft.Outlook.Response.Read

• Microsoft.Outlook.Response.Compose

• Microsoft.Outlook.Response.CounterPropose

• Microsoft.Outlook.RSS

• Microsoft.Outlook.Post.Read

• Microsoft.Outlook.Post.Compose

• Microsoft.Outlook.DistributionList

• Microsoft.Outlook.Report

• Microsoft.Outlook.Resend

• Microsoft.Outlook.Response.Read

• Microsoft.Outlook.Response.Compose

• Microsoft.Outlook.Response.CounterPropose

• Microsoft.Outlook.RSS

• Microsoft.Outlook.Post.Read

• Microsoft.Outlook.Post.Compose

• Microsoft.Outlook.Sharing.Read

• Microsoft.Outlook.Sharing.Compose

0 0

Post a comment