// OnMyButtonClick routine handles all button click events
 // and displays IRibbonControl.Context in message box
 public void OnMyButtonClick(Office.IRibbonControl control)
 {
     string msg = string.Empty;
     if (control.Context is Outlook.AttachmentSelection)
     {
         msg = "Context=AttachmentSelection" + "\n";
         Outlook.AttachmentSelection attachSel =
             control.Context as Outlook.AttachmentSelection;
         foreach (Outlook.Attachment attach in attachSel)
         {
             msg = msg + attach.DisplayName + "\n";
         }
     }
     else if (control.Context is Outlook.Folder)
     {
         msg = "Context=Folder" + "\n";
         Outlook.Folder folder =
             control.Context as Outlook.Folder;
         msg = msg + folder.Name;
     }
     else if (control.Context is Outlook.Selection)
     {
         msg = "Context=Selection" + "\n";
         Outlook.Selection selection =
             control.Context as Outlook.Selection;
         if (selection.Count == 1)
         {
             OutlookItem olItem =
                 new OutlookItem(selection[1]);
             msg = msg + olItem.Subject
                 + "\n" + olItem.LastModificationTime;
         }
         else
         {
             msg = msg + "Multiple Selection Count="
                 + selection.Count;
         }
     }
     else if (control.Context is Outlook.OutlookBarShortcut)
     {
         msg = "Context=OutlookBarShortcut" + "\n";
         Outlook.OutlookBarShortcut shortcut =
             control.Context as Outlook.OutlookBarShortcut;
         msg = msg + shortcut.Name;
     }
     else if (control.Context is Outlook.Store)
     {
         msg = "Context=Store" + "\n";
         Outlook.Store store =
             control.Context as Outlook.Store;
         msg = msg + store.DisplayName;
     }
     else if (control.Context is Outlook.View)
     {
         msg = "Context=View" + "\n";
         Outlook.View view =
             control.Context as Outlook.View;
         msg = msg + view.Name;
     }
     else if (control.Context is Outlook.Inspector)
     {
         msg = "Context=Inspector" + "\n";
         Outlook.Inspector insp =
             control.Context as Outlook.Inspector;
         if (insp.AttachmentSelection.Count >= 1)
         {
             Outlook.AttachmentSelection attachSel =
                 insp.AttachmentSelection;
             foreach (Outlook.Attachment attach in attachSel)
             {
                 msg = msg + attach.DisplayName + "\n";
             }
         }
         else
         {
             OutlookItem olItem =
                 new OutlookItem(insp.CurrentItem);
             msg = msg + olItem.Subject;
         }
     }
     else if (control.Context is Outlook.Explorer)
     {
         msg = "Context=Explorer" + "\n";
         Outlook.Explorer explorer =
             control.Context as Outlook.Explorer;
         if (explorer.AttachmentSelection.Count >= 1)
         {
             Outlook.AttachmentSelection attachSel =
                 explorer.AttachmentSelection;
             foreach (Outlook.Attachment attach in attachSel)
             {
                 msg = msg + attach.DisplayName + "\n";
             }
         }
         else
         {
             Outlook.Selection selection =
                 explorer.Selection;
             if (selection.Count == 1)
             {
                 OutlookItem olItem =
                     new OutlookItem(selection[1]);
                 msg = msg + olItem.Subject
                     + "\n" + olItem.LastModificationTime;
             }
             else
             {
                 msg = msg + "Multiple Selection Count="
                     + selection.Count;
             }
         }
     }
     else if (control.Context is Outlook.NavigationGroup)
     {
         msg = "Context=NavigationGroup" + "\n";
         Outlook.NavigationGroup navGroup =
             control.Context as Outlook.NavigationGroup;
         msg = msg + navGroup.Name;
     }
     else if (control.Context is
         Microsoft.Office.Core.IMsoContactCard)
     {
         msg = "Context=IMsoContactCard" + "\n";
         Office.IMsoContactCard card =
             control.Context as Office.IMsoContactCard;
         if (card.AddressType ==
             Office.MsoContactCardAddressType.
             msoContactCardAddressTypeOutlook)
         {
             // IMSOContactCard.Address is AddressEntry.ID
             Outlook.AddressEntry addr =
                 Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(
                 card.Address);
             if (addr != null)
             {
                 msg = msg + addr.Name;
             }
         }
     }
     else if (control.Context is Outlook.NavigationModule)
     {
         msg = "Context=NavigationModule";
     }
     else if (control.Context == null)
     {
         msg = "Context=Null";
     }
     else
     {
         msg = "Context=Unknown";
     }
     MessageBox.Show(msg,
         "RibbonXOutlook14AddinCS",
         MessageBoxButtons.OK,
         MessageBoxIcon.Information);
 }
Exemple #2
0
        // OnMyButtonClick routine handles all button click events
        // and displays IRibbonControl.Context in message box
        public void OnMyButtonClick(Office.IRibbonControl control)
        {
            string msg = string.Empty;

            if (control.Context is Outlook.AttachmentSelection)
            {
                msg = "Context=AttachmentSelection" + "\n";
                Outlook.AttachmentSelection attachSel =
                    control.Context as Outlook.AttachmentSelection;
                foreach (Outlook.Attachment attach in attachSel)
                {
                    msg = msg + attach.DisplayName + "\n";
                }
            }
            else if (control.Context is Outlook.Folder)
            {
                msg = "Context=Folder" + "\n";
                Outlook.Folder folder =
                    control.Context as Outlook.Folder;
                msg = msg + folder.Name;
            }
            else if (control.Context is Outlook.Selection)
            {
                msg = "Context=Selection" + "\n";
                Outlook.Selection selection =
                    control.Context as Outlook.Selection;
                if (selection.Count == 1)
                {
                    OutlookItem olItem =
                        new OutlookItem(selection[1]);
                    msg = msg + olItem.Subject
                          + "\n" + olItem.LastModificationTime;
                }
                else
                {
                    msg = msg + "Multiple Selection Count="
                          + selection.Count;
                }
            }
            else if (control.Context is Outlook.OutlookBarShortcut)
            {
                msg = "Context=OutlookBarShortcut" + "\n";
                Outlook.OutlookBarShortcut shortcut =
                    control.Context as Outlook.OutlookBarShortcut;
                msg = msg + shortcut.Name;
            }
            else if (control.Context is Outlook.Store)
            {
                msg = "Context=Store" + "\n";
                Outlook.Store store =
                    control.Context as Outlook.Store;
                msg = msg + store.DisplayName;
            }
            else if (control.Context is Outlook.View)
            {
                msg = "Context=View" + "\n";
                Outlook.View view =
                    control.Context as Outlook.View;
                msg = msg + view.Name;
            }
            else if (control.Context is Outlook.Inspector)
            {
                msg = "Context=Inspector" + "\n";
                Outlook.Inspector insp =
                    control.Context as Outlook.Inspector;
                if (insp.AttachmentSelection.Count >= 1)
                {
                    Outlook.AttachmentSelection attachSel =
                        insp.AttachmentSelection;
                    foreach (Outlook.Attachment attach in attachSel)
                    {
                        msg = msg + attach.DisplayName + "\n";
                    }
                }
                else
                {
                    OutlookItem olItem =
                        new OutlookItem(insp.CurrentItem);
                    msg = msg + olItem.Subject;
                }
            }
            else if (control.Context is Outlook.Explorer)
            {
                msg = "Context=Explorer" + "\n";
                Outlook.Explorer explorer =
                    control.Context as Outlook.Explorer;
                if (explorer.AttachmentSelection.Count >= 1)
                {
                    Outlook.AttachmentSelection attachSel =
                        explorer.AttachmentSelection;
                    foreach (Outlook.Attachment attach in attachSel)
                    {
                        msg = msg + attach.DisplayName + "\n";
                    }
                }
                else
                {
                    Outlook.Selection selection =
                        explorer.Selection;
                    if (selection.Count == 1)
                    {
                        OutlookItem olItem =
                            new OutlookItem(selection[1]);
                        msg = msg + olItem.Subject
                              + "\n" + olItem.LastModificationTime;
                    }
                    else
                    {
                        msg = msg + "Multiple Selection Count="
                              + selection.Count;
                    }
                }
            }
            else if (control.Context is Outlook.NavigationGroup)
            {
                msg = "Context=NavigationGroup" + "\n";
                Outlook.NavigationGroup navGroup =
                    control.Context as Outlook.NavigationGroup;
                msg = msg + navGroup.Name;
            }
            else if (control.Context is
                     Microsoft.Office.Core.IMsoContactCard)
            {
                msg = "Context=IMsoContactCard" + "\n";
                Office.IMsoContactCard card =
                    control.Context as Office.IMsoContactCard;
                if (card.AddressType ==
                    Office.MsoContactCardAddressType.
                    msoContactCardAddressTypeOutlook)
                {
                    // IMSOContactCard.Address is AddressEntry.ID
                    Outlook.AddressEntry addr =
                        Globals.ThisAddIn.Application.Session.GetAddressEntryFromID(
                            card.Address);
                    if (addr != null)
                    {
                        msg = msg + addr.Name;
                    }
                }
            }
            else if (control.Context is Outlook.NavigationModule)
            {
                msg = "Context=NavigationModule";
            }
            else if (control.Context == null)
            {
                msg = "Context=Null";
            }
            else
            {
                msg = "Context=Unknown";
            }
            MessageBox.Show(msg,
                            "RibbonXOutlook14AddinCS",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
        }