Click here to Skip to main content
Click here to Skip to main content

Adding commandbar controls to outlook

By , 1 Feb 2007
 

Introduction:

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.

Overview:

Following are the structure of commandbar:

CommandBars (CommandBar)
CommandBarControls (CommandBarControl)
CommandBarButton
CommandBarCombBox
CommandBarPopup
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:

newbar.Controls.Add(MsoControlType.msoControlButton,1,"",1,true); 
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 India.
Achieved Master of Computer Application and Bachelor degree in commerce from Mumbai University, India.

License

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
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionAdding a drop down in e-mail bodymemberMember 430193914 Jul '11 - 21:20 
GeneralMy vote of 5memberkamini garg13 Jul '11 - 19:29 
QuestionHow to add sub menu for popup menumemberSwarna.060326 Mar '08 - 21:51 

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

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