Manipulation d’office en C#: Exemple d’une barre de contrôle.

Author:

Manipulation,d'office,en,C#:,Exemple,d'une,barre,de,contrôle.
{filelink=15059}

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
using Word;
using Office = Microsoft.Office.Core;

namespace ExOffice
{
  /*          Créer une barre de commande                               */
  public class CreateationCommande
  {
    [STAThread]
    static void Main(string[] args)
    {

      Office.CommandBar BarreCommande;
      Office.CommandBarButton Bouton;
      object Missing = System.Reflection.Missing.Value;
      Office._CommandBarButtonEvents_ClickEventHandler ButtonHandler;
      Word.ApplicationClass ExWord = new Word.ApplicationClass();

      ExWord.Visible = true;
      BarreCommande = ExWord.CommandBars.Add("Barre de commande Mesexemples.com", Missing, Missing, Missing);
      Bouton = (Office.CommandBarButton)BarreCommande.Controls.Add(Office.MsoControlType.msoControlButton, Missing, Missing, Missing, Missing);
      Bouton.Caption = "Mon Bouton";
      Bouton.FaceId = 1845;
      ButtonHandler = new Office._CommandBarButtonEvents_ClickEventHandler(OnClick_Button);
      Bouton.Click += ButtonHandler;
      System.Windows.Forms.Application.Run();
    }
    private static void OnClick_Button(Office.CommandBarButton ctrl, ref bool cancel)
    {
      MessageBox.Show("L'utilisateur a cliqué sur votre bouton");
    }
  }

}

Leave a Reply

Your email address will not be published. Required fields are marked *