ADD-IN is basically a software program that extends the capabilities of larger program. For example there are many outlook Add-ins and Excel Add-ins I have designed to provide more basic functionality offered by Microsoft outlook as well as Microsoft Excel. It adds graphics and communication facilities to the application.I have created Add-ins in visual studio 2003 which access the object model of Outlook 2003, use members of ThisApplication class.
ThisApplication inherits from Microsoft.Office.Tools.Outlook.Application class . This class wraps the Microsoft.Office.Interop.Outlook.Application class, which represents the Outlook application. This is the highest-level class in the Outlook object model. You can access the members of the Microsoft.Office.Interop.Outlook.Application class by using this (in C#) in the ThisApplication class. Code that is outside the ThisApplication class can access the ThisApplication object by using Globals.ThisApplication. Since all Office applications share the same commandbars, this article applies to other Office products as well.
Following are the structure of commandbar:
CommandBars collection object represent the command bars in container application.
Adding a new command bars collection.
applicationObject.ActiveExplorer().CommandBars.Add(object name, object position, object menubar, object temporary);
Here all parameters are accepting an object. Let's look it in more detail.
object name : Name of the new commandbar(string name);
object position – msobarposition position, it indicates the position of commandbar; msoBarLeft, msoBarTop, msoBarRight, msoBarBottom indicate the left, top, right, and bottom coordinates of the new command bar. msoBarFloating indicates that the new command bar won't be docked. msoBarPopup indicates that the new command bar will be a shortcut menu. msoBarMenuBar applies to Macintosh only.
object menubar : bool menubar; set it true to replace active commandbar with new commandbar, default is false.
object temporary: bool temporary; true to make the command bar temporary. Temporary command bars are deleted when the container application is closed. The default value is false.
Adding command bar control to the commandbar collection:
Adding a CommandBar to the CommandBars collections returns us a reference to the newly created command bar.
CommandBar myCommandBar = applicationObject.ActiveExplorer().CommandBars.Add ("custom", MsoBarPosition.msoBarTop,false,true); myCommandBar.visible = true;
Adding button control:
Now we can add a button control on allready created commandbar control myCommandBar. Following code is basically used to add button on this command bar.
CommandBarControl cmdBarControl2 = myCommandBar.Controls.Add(MsoControlType.msoControlButton,1,"",Missing.Value,true);
cmdBarControl2.Visible = true;
cmdBarControl2.Caption ="My Test button";
After adding adding button on this control we want to add event handler on clik of this button.
CommandBarButton btnclickhandler = (CommandBarButton)cmdBarControl2;
btnclickhandler.Click +=new CommandBarButtonEvents_ClickEventHandler(btnclickhandler _Click);
btnclickhandler _Click() is a function that will handle click event.
Adding Pop Up control:
After that we can added pop up menu to commandbar Control. These controls are of type CommandBarControl and added as pop up button on CommandBarControl object.
CommandBarControl cmdBarControl = myCommandBar.Controls.Add(MsoControlType.msoControlPopup,1,"",1,true);
cmdBarControl.Visible = true;
cmdBarControl.Caption ="PopUp Control";
CommandBarPopup popup = (CommandBarPopup)cmdBarControl;
CommandBar newbar = popup.CommandBar;
Addind popup button on this popup control:
mybarhost.Visible = true;
mybarhost.Caption = "Popup button";
Again if we want to add event handler on click of this button we can do it as
buttonhost.Click +=new _CommandBarButtonEvents_ClickEventHandler(buttonhost_Click);
In my next article I will discuss how to add images on button control.
Dotnet developer working with software Development Company in <place w:st="on" /><country-region w:st="on" />India</country-region /></place />.
Achieved Master of Computer Application and Bachelor degree in commerce from <place w:st="on" /><city w:st="on" />Mumbai University</city />, <country-region w:st="on" />India</country-region /></place />.