1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using System.Reflection;
using System.IO;
using System.Text;
using System.Collections.Generic;
namespace OutlookAddIn2007
{
public partial class ThisAddIn
{
// La bar de menu
private Office.CommandBar cbar = null;
// Les items de la barre
private Office.CommandBarButton cbShowConnectionForm = null;
// Les évènements qui se produisent lors du clic sur les items de la barre
private Office._CommandBarButtonEvents_ClickEventHandler cbShowConnectionFormClickEvent;
private Microsoft.Office.Interop.Outlook.Inspectors objInspectors;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// On peut omettre les paramètres optionnels
object oMissing = System.Reflection.Missing.Value;
// Texte de la barre de menu + position
cbar = this.Application.ActiveExplorer().CommandBars.Add("Adneom Addin", Office.MsoBarPosition.msoBarTop, oMissing, (object)true);
// Ajout d'un nouveau bouton
cbShowConnectionForm = (Office.CommandBarButton)(cbar.Controls.Add((object)1, oMissing, oMissing, oMissing, oMissing));
objInspectors = this.Application.Inspectors;
objInspectors.NewInspector += new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(objInspectors_NewInspector);
AddCustomUI();
// Méthode à appeller lors du clic sur l'item
cbShowConnectionFormClickEvent = new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(
cbShowConnectionFormClickEvent_Click);
cbShowConnectionForm.Click += cbShowConnectionFormClickEvent;
// On affiche la barre de menu
cbar.Visible = true;
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
private void objInspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
AddCustomUI();
}
private void AddCustomUI()
{
try
{
if (this.Application.ActiveExplorer().Selection.Count > 0)
{
Object selObject = this.Application.ActiveExplorer().Selection[1];
if (selObject is Outlook.MailItem)
{
Outlook.MailItem mailItem = (selObject as Outlook.MailItem);
StyleCommandBar("Mail");
}
else
{
StyleCommandBar("Other");
}
}
}
catch
{
StyleCommandBar("Erreur");
}
}
private void StyleCommandBar(string text)
{
// Définition du style de bouton;
cbShowConnectionForm.Style = Office.MsoButtonStyle.msoButtonCaption;
// Définition de sa propriété Caption (Texte à afficher)
cbShowConnectionForm.Caption = String.Format(text);
}
private void cbShowConnectionFormClickEvent_Click(Office.CommandBarButton sender, ref bool Cancel)
{
//Outlook.MAPIFolder selectedFolder = this.Application.ActiveExplorer().CurrentFolder;
try
{
if (this.Application.ActiveExplorer().Selection.Count > 0)
{
Object selObject = this.Application.ActiveExplorer().Selection[1];
if (selObject is Outlook.MailItem)
{
Outlook.MailItem mailItem = (selObject as Outlook.MailItem);
Email frmEmail = new Email(mailItem);
frmEmail.ShowDialog();
}
else if (selObject is Outlook.ContactItem)
{
Outlook.ContactItem contactItem = (selObject as Outlook.ContactItem);
Contact frmContact = new Contact(contactItem);
frmContact.ShowDialog();
}
else if (selObject is Outlook.AppointmentItem)
{
Outlook.AppointmentItem apptItem = (selObject as Outlook.AppointmentItem);
Appointment frmAppointment = new Appointment(apptItem);
frmAppointment.ShowDialog();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Erreur !" + ex, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
#region Code généré par VSTO
/// <summary>
/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
/// le contenu de cette méthode avec l'éditeur de code.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
} |
Partager