Click here to Skip to main content
13,348,874 members (76,223 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 1 Feb 2007

Adding commandbar controls to outlook

, 1 Feb 2007
Rate this:
Please Sign up or sign in to vote.
Adding buttons, events on outlook application


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 (CommandBar)
CommandBarControls (CommandBarControl)
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.

About Kamlesh

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 />.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Kamlesh Singh
Software Developer
India India
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionAdd .Net control to Command bar Pin
himanshub197818-Sep-13 1:01
memberhimanshub197818-Sep-13 1:01 
QuestionAdding a drop down in e-mail body Pin
Member 430193914-Jul-11 22:20
memberMember 430193914-Jul-11 22:20 
GeneralMy vote of 5 Pin
kamini garg13-Jul-11 20:29
memberkamini garg13-Jul-11 20:29 
QuestionHow to add sub menu for popup menu Pin
Swarna.060326-Mar-08 22:51
memberSwarna.060326-Mar-08 22:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 2 Feb 2007
Article Copyright 2007 by Kamlesh Singh
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid