Adding Two button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kannan

    Adding Two button

    Hi,
    I am trying to created Outloook Add-in Com in outlook using C#.
    I have seen this URL for developing this sample

    Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.


    When I executed this program it created new custom button called "My Custom
    Button" in the Outlook menu bar.

    But when I tried to create one more button called "Forward Mail" (code is
    very similar to "My custom button" code) but it is not displaying in
    outlook.
    Anybody knows that what I am doing wrong.

    Sorry I am new to C# and outlook.

    Thanks in advance.

    kannan.
  • Morten Wennevik

    #2
    Re: Adding Two button

    Hi Kannan,

    It will help immensly if you could show us your code, or at least the
    difference between your code and the msdn code


    On Mon, 09 Oct 2006 14:31:02 +0200, Kannan
    <Kannan@discuss ions.microsoft. comwrote:
    Hi,
    I am trying to created Outloook Add-in Com in outlook using C#.
    I have seen this URL for developing this sample
    >
    Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.

    >
    When I executed this program it created new custom button called "My
    Custom
    Button" in the Outlook menu bar.
    >
    But when I tried to create one more button called "Forward Mail" (codeis
    very similar to "My custom button" code) but it is not displaying in
    outlook.
    Anybody knows that what I am doing wrong.
    >
    Sorry I am new to C# and outlook.
    >
    Thanks in advance.
    >
    kannan.


    --
    Happy Coding!
    Morten Wennevik [C# MVP]

    Comment

    • Kannan

      #3
      Re: Adding Two button

      Here is my full Code: I have commented my new button ForwardButton.

      Thanks for your help....

      Kannan.

      namespace MyCOMAddin1
      {
      using System;
      using Microsoft.Offic e.Core;
      using Extensibility;
      using System.Runtime. InteropServices ;
      using System.Reflecti on;
      using System.Windows. Forms;


      #region Read me for Add-in installation and setup information.
      // When run, the Add-in wizard prepared the registry for the Add-in.
      // At a later time, if the Add-in becomes unavailable for reasons such as:
      // 1) You moved this project to a computer other than which is was
      originally created on.
      // 2) You chose 'Yes' when presented with a message asking if you wish to
      remove the Add-in.
      // 3) Registry corruption.
      // you will need to re-register the Add-in by building the MyAddin21Setup
      project
      // by right clicking the project in the Solution Explorer, then choosing
      install.
      #endregion

      /// <summary>
      /// The object for implementing an Add-in.
      /// </summary>
      /// <seealso class='IDTExten sibility2' />
      [GuidAttribute(" 1672C7A6-0014-4DA6-930B-83859D338C5F"),
      ProgId("MyCOMAd din1.Connect")]
      public class Connect : Object, Extensibility.I DTExtensibility 2
      {
      /// <summary>
      /// Implements the constructor for the Add-in object.
      /// Place your initialization code within this method.
      /// </summary>
      private CommandBarButto n MyButton;
      private CommandBarButto n ForwardButton;

      public Connect()
      {



      }

      /// <summary>
      /// Implements the OnConnection method of the IDTExtensibilit y2
      interface.
      /// Receives notification that the Add-in is being loaded.
      /// </summary>
      /// <param term='applicati on'>
      /// Root object of the host application.
      /// </param>
      /// <param term='connectMo de'>
      /// Describes how the Add-in is being loaded.
      /// </param>
      /// <param term='addInInst '>
      /// Object representing this Add-in.
      /// </param>
      /// <seealso class='IDTExten sibility2' />
      public void OnConnection(ob ject application, Extensibility.e xt_ConnectMode
      connectMode, object addInInst, ref System.Array custom)
      {

      applicationObje ct = application;
      addInInstance = addInInst;

      if(connectMode != Extensibility.e xt_ConnectMode. ext_cm_Startup)
      {
      OnStartupComple te(ref custom);
      }
      }

      /// <summary>
      /// Implements the OnDisconnection method of the IDTExtensibilit y2
      interface.
      /// Receives notification that the Add-in is being unloaded.
      /// </summary>
      /// <param term='disconnec tMode'>
      /// Describes how the Add-in is being unloaded.
      /// </param>
      /// <param term='custom'>
      /// Array of parameters that are host application specific.
      /// </param>
      /// <seealso class='IDTExten sibility2' />
      public void OnDisconnection (Extensibility. ext_DisconnectM ode
      disconnectMode, ref System.Array custom)
      {
      if(disconnectMo de != Extensibility.e xt_DisconnectMo de.ext_dm_HostS hutdown)
      {
      OnBeginShutdown (ref custom);
      }
      applicationObje ct = null;
      }

      /// <summary>
      /// Implements the OnAddInsUpdate method of the IDTExtensibilit y2
      interface.
      /// Receives notification that the collection of Add-ins has changed.
      /// </summary>
      /// <param term='custom'>
      /// Array of parameters that are host application specific.
      /// </param>
      /// <seealso class='IDTExten sibility2' />
      public void OnAddInsUpdate( ref System.Array custom)
      {
      }

      /// <summary>
      /// Implements the OnStartupComple te method of the IDTExtensibilit y2
      interface.
      /// Receives notification that the host application has completed
      loading.
      /// </summary>
      /// <param term='custom'>
      /// Array of parameters that are host application specific.
      /// </param>
      /// <seealso class='IDTExten sibility2' />
      public void OnStartupComple te(ref System.Array custom)
      {
      CommandBars oCommandBars;
      CommandBar oStandardBar;

      try
      {
      oCommandBars =
      (CommandBars)ap plicationObject .GetType().Invo keMember("Comma ndBars",
      BindingFlags.Ge tProperty , null, applicationObje ct ,null);
      }
      catch(Exception )
      {
      // Outlook has the CommandBars collection on the Explorer object.
      object oActiveExplorer ;
      oActiveExplorer =
      applicationObje ct.GetType().In vokeMember("Act iveExplorer",Bi ndingFlags.GetP roperty,null,ap plicationObject ,null);
      oCommandBars=
      (CommandBars)oA ctiveExplorer.G etType().Invoke Member("Command Bars",BindingFl ags.GetProperty ,null,oActiveEx plorer,null);
      }

      // Set up a custom button on the "Standard" commandbar.
      try
      {
      oStandardBar = oCommandBars["Standard"];
      }
      catch(Exception )
      {
      // Access names its main toolbar Database.
      oStandardBar = oCommandBars["Database"];
      }

      // In case the button was not deleted, use the exiting one.
      try
      {
      MyButton = (CommandBarButt on)oStandardBar .Controls["Process Contacts"];
      //ForwardButton = (CommandBarButt on)oStandardBar .Controls["Forward Mail"];
      }
      catch(Exception )
      {
      object omissing = System.Reflecti on.Missing.Valu e ;
      MyButton = (CommandBarButt on) oStandardBar.Co ntrols.Add(1, omissing ,
      omissing , omissing , omissing);
      //ForwardButton = (CommandBarButt on) oStandardBar.Co ntrols.Add(2,
      omissing , omissing , omissing , omissing);

      MyButton.Captio n = "Process Contacts";
      MyButton.Style = MsoButtonStyle. msoButtonCaptio n;
      }

      // The following items are optional, but recommended.
      //The Tag property lets you quickly find the control
      //and helps MSO keep track of it when more than
      //one application window is visible. The property is required
      //by some Office applications and should be provided.
      MyButton.Tag = "Process Contacts";
      //ForwardButton.T ag = "Forward Mail";

      // The OnAction property is optional but recommended.
      //It should be set to the ProgID of the add-in, so that if
      //the add-in is not loaded when a user presses the button,
      //MSO loads the add-in automatically and then raises
      //the Click event for the add-in to handle.
      MyButton.OnActi on = "!<MyCOMAddin1. Connect>";
      //ForwardButton.O nAction = "!<MyCOMAddin.C onnect>";

      MyButton.Visibl e = true;

      //ForwardButton.V isible = true;
      MyButton.Click += new
      Microsoft.Offic e.Core._Command BarButtonEvents _ClickEventHand ler(this.MyButt on_Click);
      //ForwardButton.C lick += new
      Microsoft.Offic e.Core._Command BarButtonEvents _ClickEventHand ler(this.Forwar dMail_Click);


      object oName =
      applicationObje ct.GetType().In vokeMember("Nam e",BindingFlags .GetProperty,nu ll,applicationO bject,null);

      // Display a simple message to show which application you started in.
      System.Windows. Forms.MessageBo x.Show("This Addin is loaded by " +
      oName.ToString( ) , "MyCOMAddin ");
      oStandardBar = null;
      oCommandBars = null;

      }

      /// <summary>
      /// Implements the OnBeginShutdown method of the IDTExtensibilit y2
      interface.
      /// Receives notification that the host application is being unloaded.
      /// </summary>
      /// <param term='custom'>
      /// Array of parameters that are host application specific.
      /// </param>
      /// <seealso class='IDTExten sibility2' />
      public void OnBeginShutdown (ref System.Array custom)
      {
      object omissing = System.Reflecti on.Missing.Valu e ;
      MyButton.Delete (omissing);
      //ForwardButton.D elete(omissing) ;
      MyButton = null;
      //ForwardButton = null;
      }

      private void MyButton_Click( CommandBarButto n cmdBarbutton,re f bool cancel)
      {
      MessageBox.Show ("Final Version","MyCOM Addin");
      }

      // private void ForwardMail_Cli ck(CommandBarBu tton cmdBarbutton,re f bool
      cancel)
      // {
      // MessageBox.Show ("Forward Button clicked");
      // }


      private object applicationObje ct;
      private object addInInstance;
      }
      }

      "Morten Wennevik" wrote:
      Hi Kannan,
      >
      It will help immensly if you could show us your code, or at least the
      difference between your code and the msdn code
      >
      >
      On Mon, 09 Oct 2006 14:31:02 +0200, Kannan
      <Kannan@discuss ions.microsoft. comwrote:
      >
      Hi,
      I am trying to created Outloook Add-in Com in outlook using C#.
      I have seen this URL for developing this sample

      Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.


      When I executed this program it created new custom button called "My
      Custom
      Button" in the Outlook menu bar.

      But when I tried to create one more button called "Forward Mail" (code is
      very similar to "My custom button" code) but it is not displaying in
      outlook.
      Anybody knows that what I am doing wrong.

      Sorry I am new to C# and outlook.

      Thanks in advance.

      kannan.
      >
      >
      >
      --
      Happy Coding!
      Morten Wennevik [C# MVP]
      >

      Comment

      • Kannan

        #4
        Re: Adding Two button

        Hi,
        Please ignore this problem. I have solved it. Thanks for your help.

        Thanks,
        Kannan

        "Kannan" wrote:
        Here is my full Code: I have commented my new button ForwardButton.
        >
        Thanks for your help....
        >
        Kannan.
        >
        namespace MyCOMAddin1
        {
        using System;
        using Microsoft.Offic e.Core;
        using Extensibility;
        using System.Runtime. InteropServices ;
        using System.Reflecti on;
        using System.Windows. Forms;
        >
        >
        #region Read me for Add-in installation and setup information.
        // When run, the Add-in wizard prepared the registry for the Add-in.
        // At a later time, if the Add-in becomes unavailable for reasons such as:
        // 1) You moved this project to a computer other than which is was
        originally created on.
        // 2) You chose 'Yes' when presented with a message asking if you wish to
        remove the Add-in.
        // 3) Registry corruption.
        // you will need to re-register the Add-in by building the MyAddin21Setup
        project
        // by right clicking the project in the Solution Explorer, then choosing
        install.
        #endregion
        >
        /// <summary>
        /// The object for implementing an Add-in.
        /// </summary>
        /// <seealso class='IDTExten sibility2' />
        [GuidAttribute(" 1672C7A6-0014-4DA6-930B-83859D338C5F"),
        ProgId("MyCOMAd din1.Connect")]
        public class Connect : Object, Extensibility.I DTExtensibility 2
        {
        /// <summary>
        /// Implements the constructor for the Add-in object.
        /// Place your initialization code within this method.
        /// </summary>
        private CommandBarButto n MyButton;
        private CommandBarButto n ForwardButton;
        >
        public Connect()
        {
        >
        >
        >
        }
        >
        /// <summary>
        /// Implements the OnConnection method of the IDTExtensibilit y2
        interface.
        /// Receives notification that the Add-in is being loaded.
        /// </summary>
        /// <param term='applicati on'>
        /// Root object of the host application.
        /// </param>
        /// <param term='connectMo de'>
        /// Describes how the Add-in is being loaded.
        /// </param>
        /// <param term='addInInst '>
        /// Object representing this Add-in.
        /// </param>
        /// <seealso class='IDTExten sibility2' />
        public void OnConnection(ob ject application, Extensibility.e xt_ConnectMode
        connectMode, object addInInst, ref System.Array custom)
        {
        >
        applicationObje ct = application;
        addInInstance = addInInst;
        >
        if(connectMode != Extensibility.e xt_ConnectMode. ext_cm_Startup)
        {
        OnStartupComple te(ref custom);
        }
        }
        >
        /// <summary>
        /// Implements the OnDisconnection method of the IDTExtensibilit y2
        interface.
        /// Receives notification that the Add-in is being unloaded.
        /// </summary>
        /// <param term='disconnec tMode'>
        /// Describes how the Add-in is being unloaded.
        /// </param>
        /// <param term='custom'>
        /// Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExten sibility2' />
        public void OnDisconnection (Extensibility. ext_DisconnectM ode
        disconnectMode, ref System.Array custom)
        {
        if(disconnectMo de != Extensibility.e xt_DisconnectMo de.ext_dm_HostS hutdown)
        {
        OnBeginShutdown (ref custom);
        }
        applicationObje ct = null;
        }
        >
        /// <summary>
        /// Implements the OnAddInsUpdate method of the IDTExtensibilit y2
        interface.
        /// Receives notification that the collection of Add-ins has changed.
        /// </summary>
        /// <param term='custom'>
        /// Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExten sibility2' />
        public void OnAddInsUpdate( ref System.Array custom)
        {
        }
        >
        /// <summary>
        /// Implements the OnStartupComple te method of the IDTExtensibilit y2
        interface.
        /// Receives notification that the host application has completed
        loading.
        /// </summary>
        /// <param term='custom'>
        /// Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExten sibility2' />
        public void OnStartupComple te(ref System.Array custom)
        {
        CommandBars oCommandBars;
        CommandBar oStandardBar;
        >
        try
        {
        oCommandBars =
        (CommandBars)ap plicationObject .GetType().Invo keMember("Comma ndBars",
        BindingFlags.Ge tProperty , null, applicationObje ct ,null);
        }
        catch(Exception )
        {
        // Outlook has the CommandBars collection on the Explorer object.
        object oActiveExplorer ;
        oActiveExplorer =
        applicationObje ct.GetType().In vokeMember("Act iveExplorer",Bi ndingFlags.GetP roperty,null,ap plicationObject ,null);
        oCommandBars=
        (CommandBars)oA ctiveExplorer.G etType().Invoke Member("Command Bars",BindingFl ags.GetProperty ,null,oActiveEx plorer,null);
        }
        >
        // Set up a custom button on the "Standard" commandbar.
        try
        {
        oStandardBar = oCommandBars["Standard"];
        }
        catch(Exception )
        {
        // Access names its main toolbar Database.
        oStandardBar = oCommandBars["Database"];
        }
        >
        // In case the button was not deleted, use the exiting one.
        try
        {
        MyButton = (CommandBarButt on)oStandardBar .Controls["Process Contacts"];
        //ForwardButton = (CommandBarButt on)oStandardBar .Controls["Forward Mail"];
        }
        catch(Exception )
        {
        object omissing = System.Reflecti on.Missing.Valu e ;
        MyButton = (CommandBarButt on) oStandardBar.Co ntrols.Add(1, omissing ,
        omissing , omissing , omissing);
        //ForwardButton = (CommandBarButt on) oStandardBar.Co ntrols.Add(2,
        omissing , omissing , omissing , omissing);
        >
        MyButton.Captio n = "Process Contacts";
        MyButton.Style = MsoButtonStyle. msoButtonCaptio n;
        }
        >
        // The following items are optional, but recommended.
        //The Tag property lets you quickly find the control
        //and helps MSO keep track of it when more than
        //one application window is visible. The property is required
        //by some Office applications and should be provided.
        MyButton.Tag = "Process Contacts";
        //ForwardButton.T ag = "Forward Mail";
        >
        // The OnAction property is optional but recommended.
        //It should be set to the ProgID of the add-in, so that if
        //the add-in is not loaded when a user presses the button,
        //MSO loads the add-in automatically and then raises
        //the Click event for the add-in to handle.
        MyButton.OnActi on = "!<MyCOMAddin1. Connect>";
        //ForwardButton.O nAction = "!<MyCOMAddin.C onnect>";
        >
        MyButton.Visibl e = true;
        >
        //ForwardButton.V isible = true;
        MyButton.Click += new
        Microsoft.Offic e.Core._Command BarButtonEvents _ClickEventHand ler(this.MyButt on_Click);
        //ForwardButton.C lick += new
        Microsoft.Offic e.Core._Command BarButtonEvents _ClickEventHand ler(this.Forwar dMail_Click);
        >
        >
        object oName =
        applicationObje ct.GetType().In vokeMember("Nam e",BindingFlags .GetProperty,nu ll,applicationO bject,null);
        >
        // Display a simple message to show which application you started in.
        System.Windows. Forms.MessageBo x.Show("This Addin is loaded by " +
        oName.ToString( ) , "MyCOMAddin ");
        oStandardBar = null;
        oCommandBars = null;
        >
        }
        >
        /// <summary>
        /// Implements the OnBeginShutdown method of the IDTExtensibilit y2
        interface.
        /// Receives notification that the host application is being unloaded.
        /// </summary>
        /// <param term='custom'>
        /// Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExten sibility2' />
        public void OnBeginShutdown (ref System.Array custom)
        {
        object omissing = System.Reflecti on.Missing.Valu e ;
        MyButton.Delete (omissing);
        //ForwardButton.D elete(omissing) ;
        MyButton = null;
        //ForwardButton = null;
        }
        >
        private void MyButton_Click( CommandBarButto n cmdBarbutton,re f bool cancel)
        {
        MessageBox.Show ("Final Version","MyCOM Addin");
        }
        >
        // private void ForwardMail_Cli ck(CommandBarBu tton cmdBarbutton,re f bool
        cancel)
        // {
        // MessageBox.Show ("Forward Button clicked");
        // }
        >
        >
        private object applicationObje ct;
        private object addInInstance;
        }
        }
        >
        "Morten Wennevik" wrote:
        >
        Hi Kannan,

        It will help immensly if you could show us your code, or at least the
        difference between your code and the msdn code


        On Mon, 09 Oct 2006 14:31:02 +0200, Kannan
        <Kannan@discuss ions.microsoft. comwrote:
        Hi,
        I am trying to created Outloook Add-in Com in outlook using C#.
        I have seen this URL for developing this sample
        >
        Microsoft Support is here to help you with Microsoft products. Find how-to articles, videos, and training for Microsoft Copilot, Microsoft 365, Windows 11, Surface, and more.

        >
        When I executed this program it created new custom button called "My
        Custom
        Button" in the Outlook menu bar.
        >
        But when I tried to create one more button called "Forward Mail" (code is
        very similar to "My custom button" code) but it is not displaying in
        outlook.
        Anybody knows that what I am doing wrong.
        >
        Sorry I am new to C# and outlook.
        >
        Thanks in advance.
        >
        kannan.


        --
        Happy Coding!
        Morten Wennevik [C# MVP]

        Comment

        Working...