How to add custom button, checkbox, combo box, image, tree-view.
Customize Outlook toolbar in .NET with your controls.

Toolbar Controls
for Microsoft® Office


Add-in Express Home > Toolbar Controls for Office > Online Guide > Adding controls to Outlook toolbar

Create advanced command bar controls for Outlook

Add a custom control to Outlook toolbar - Video With the Toolbar Controls for Microsoft Office you can add any controls, such as button, tree-view, combo and check box, grid, label or image to your Outlook toolbar. In the Outlook example below we are going to add a check box to a new right-docked commandbar on the Outlook Inspector window. This checkbox, BossCheckbox :-) will allow you to add your boss's e-mail address to the BCC field.

This sample is written in VB.NET, but you can develop your Outlook controls in C#, C++ and RO Chrome. Also, this example was created implying that you have some experience in using Add-in Express for developing Microsoft Outlook add-ins as well as some experience with the Microsoft Office object models. With Add-in Express you customize the Outlook 2007 toolbar as well as toolbars of Outlook 2003, 2002 (XP) and Outlook 2000 with any .NET controls.

Example of creating a custom control for Outlook toolbar

To replicate the example, you create a new Outlook add-in project or open the exiting one, add an ADXOlInspectorCommandBar to the add-in module and set adxMsoBarBottom to the Position property of the added command bar. Next step is to add an Outlook Control Adapter.

1. Add an Outlook Control Adapter

As described above, the Toolbar Controls for Microsoft Office supports Office applications though special components that we call Control Adapters. You can find them on the "Toolbar Controls for Microsoft Office" tab of the Toolbox.

The first step in using non-Office controls in your add-in is adding the corresponding control adapter to your add-in module. In this case we use an ADXOutlookControlAdapter. Read more about Control Adapters.

Adding a control adapter

2. Add your custom control to Outlook toolbar

The add-in module can contain any components including controls. So, you can add a check box (BossCheckBox) directly to your add-in module and customize the checkbox in any way you like.

Adding a control

Then, you can customize the checkbox. For example, like this:

VB.NET (from #Region "Component Designer generated code")


Me.BossCheckbox.BackColor = System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), _

CType(CType(128, Byte), Integer), CType(CType(0, Byte), Integer))
Me.BossCheckbox.Location = New System.Drawing.Point(0, 0)
Me.BossCheckbox.Name = "BossCheckbox"
Me.BossCheckbox.Size = New System.Drawing.Size(150, 24)
Me.BossCheckbox.TabIndex = 0
Me.BossCheckbox.Text = "BCC to my Boss"
Me.BossCheckbox.UseVisualStyleBackColor = False

3. Handle your control events

To BCC a message to your boss you need to handle the checkbox. We usually use the following code to BCC messages to our boss. Please note we do not touch Outlook programming here.

VB.NET


Private Sub BossCheckbox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
   If OutlookApp IsNot Nothing Then
      Dim Inspector As Outlook.Inspector = OutlookApp.ActiveInspector
      Dim Item As Outlook.MailItem = CType(Inspector.CurrentItem, Outlook.MailItem)
      If Not Item.Sent Then
         Dim ActualCheckBox As System.Windows.Forms.CheckBox = sender
         If ActualCheckBox.Checked Then
            Item.BCC = "myboss@mydomain.com"
         Else
            Item.BCC = ""
         End If
      End If
      Marshal.ReleaseComObject(Item)
      Marshal.ReleaseComObject(Inspector)
   End If
End Sub

4. Bind your control to Outlook commandbar

To bind BossCheckBox to the Outlook toolbar, you add an advanced command bar control (ADXCommandBarAdvancedControl1) to the Controls collection of your Outlook Inspector toolbar and select BossCheckBox in the Control property of the ADXCommandBarAdvancedControl1. That's all.

Binding your control to a command bar

You have done all necessary steps to place your checkbox on your Outlook commandbar. Below we give the complete code of the InitializeComponent method of our add-in module:

VB.NET


Private Sub InitializeComponent() 
Me.components = New System.ComponentModel.Container
Me.AdxOutlookControlAdapter1 = New _

AddinExpress.ToolbarControls.ADXOutlookControlAdapter(Me.components)
Me.AdxOlInspectorCommandBar1 = _
      New AddinExpress.MSO.ADXOlInspectorCommandBar(Me.components)
Me.BossCheckbox = New System.Windows.Forms.CheckBox
Me.AdxCommandBarAdvancedControl1 = _
      New AddinExpress.MSO.ADXCommandBarAdvancedControl(Me.components)
'
'AdxOlInspectorCommandBar1
Me.AdxOlInspectorCommandBar1.CommandBarName = _
      "AdxOlInspectorCommandBar1"
Me.AdxOlInspectorCommandBar1.CommandBarTag = _
      "6e212933-5790-40f5-8c25-4dd46c632f91"
Me.AdxOlInspectorCommandBar1.Controls.Add( _
       Me.AdxCommandBarAdvancedControl1)
Me.AdxOlInspectorCommandBar1.Position = _
      AddinExpress.MSO.ADXMsoBarPosition.adxMsoBarBottom
Me.AdxOlInspectorCommandBar1.Temporary = True
Me.AdxOlInspectorCommandBar1.UpdateCounter = 27
'
'BossCheckbox
Me.BossCheckbox.BackColor = _
      System.Drawing.Color.FromArgb(CType(CType(255, Byte), Integer), _
      CType(CType(128, Byte), Integer), CType(CType(0, Byte), Integer))
Me.BossCheckbox.Location = New System.Drawing.Point(0, 0)
Me.BossCheckbox.Name = "BossCheckbox"
Me.BossCheckbox.Size = New System.Drawing.Size(150, 24)
Me.BossCheckbox.TabIndex = 0
Me.BossCheckbox.Text = "BCC to my Boss"
Me.BossCheckbox.UseVisualStyleBackColor = False
'
'AdxCommandBarAdvancedControl1
Me.AdxCommandBarAdvancedControl1.Control = Me.BossCheckbox
Me.AdxCommandBarAdvancedControl1.ControlTag = _
           "f9a07d50-6dce-41b1-911e-68d694f7d7eb"
Me.AdxCommandBarAdvancedControl1.Temporary = True
Me.AdxCommandBarAdvancedControl1.UpdateCounter = 1
'
'AddinModule
Me.AddinName = "MyAddin"
Me.ShimProgID = "MyAddinShim.Proxy"
Me.SupportedApps = AddinExpress.MSO.ADXOfficeHostApp.ohaOutlook
End Sub 

5. Run your Outlook add-in

Finally, you rebuild the add-in project, run Outlook, and find your BossCheckbox:

Running the add-in

That's it! You may also want to have a look at another sample project showing how to add a custom control (DateTimePicker) to Outlook toolbar.

How Toolbar Controls works <<

>> Insight of Toolbar Controls

Back to Toolbar Controls for Office homepage




Client login

 

Login 

Password 

 

Remember me

Forgot my password