Adding a Button with a link

  • Thread starter Thread starter brianhartline
  • Start date Start date
B

brianhartline

I would like to add a button with a link to an URL to the outlook
standard toolbar. Does anyone have any sample C# code to do this?
 
I would like to add a button with a link to an URL to the outlook
standard toolbar. Does anyone have any sample C# code to do this?

I am sorry, that's very confusing...

I would like to add a button to the standard toolbar in outlook. With a
link to an URL. Does that make more sense?
 
I tried adding this code from:
http://blogs.msdn.com/dancre/archive/2004/03/21/93712.aspx

It breaks on this line: private CommandBarButton toolbarButton;

namespace outlook_add
{
using System;
using Microsoft.Office.Core;
using Extensibility;
using System.Runtime.InteropServices;


#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='IDTExtensibility2' />
[GuidAttribute("AEBC3DBE-7FD1-4A20-A65E-938DD0D075F4"),
ProgId("outlook_add.Connect")]


public class Connect : Object, Extensibility.IDTExtensibility2
{
private Microsoft.Office.Interop.Outlook.Application
applicationObject;
private object addInInstance;
private CommandBarButton toolbarButton;


/// <summary>
/// Implements the constructor for the Add-in object.
/// Place your initialization code within this method.
/// </summary>
public Connect()
{
}

/// <summary>
/// Implements the OnConnection method of the IDTExtensibility2
interface.
/// Receives notification that the Add-in is being loaded.
/// </summary>
/// <param term='application'>
/// Root object of the host application.
/// </param>
/// <param term='connectMode'>
/// Describes how the Add-in is being loaded.
/// </param>
/// <param term='addInInst'>
/// Object representing this Add-in.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst, ref
System.Array custom)
{
applicationObject =
(Microsoft.Office.Interop.Outlook.Application)application;

addInInstance = addInInst;
if(connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
{
OnStartupComplete(ref custom);
}
}

/// <summary>
/// Implements the OnDisconnection method of the
IDTExtensibility2 interface.
/// Receives notification that the Add-in is being unloaded.
/// </summary>
/// <param term='disconnectMode'>
/// Describes how the Add-in is being unloaded.
/// </param>
/// <param term='custom'>
/// Array of parameters that are host application specific.
/// </param>
/// <seealso class='IDTExtensibility2' />
public void OnDisconnection(Extensibility.ext_DisconnectMode
disconnectMode, ref System.Array custom)
{
if(disconnectMode !=
Extensibility.ext_DisconnectMode.ext_dm_HostShutdown)
{
OnBeginShutdown(ref custom);
}
applicationObject = null;
}


/// <summary>
/// Implements the OnAddInsUpdate method of the
IDTExtensibility2 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='IDTExtensibility2' />
public void OnAddInsUpdate(ref System.Array custom)
{
}

/// <summary>
/// Implements the OnStartupComplete method of the
IDTExtensibility2 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='IDTExtensibility2' />
public void OnStartupComplete(ref System.Array custom)

{
CommandBars commandBars =
applicationObject.ActiveExplorer().CommandBars;
// Create a toolbar button on the standard toolbar that calls
ToolbarButton_Click when clicked
try
{
// See if it already exists
this.toolbarButton =
(CommandBarButton)commandBars["Standard"].Controls["Hello"];
}
catch(Exception)
{
// Create it
this.toolbarButton =
(CommandBarButton)commandBars["Standard"].Controls.Add(1,
System.Reflection.Missing.Value, System.Reflection.Missing.Value,
System.Reflection.Missing.Value, System.Reflection.Missing.Value);
this.toolbarButton.Caption = "Hello";
this.toolbarButton.Style = MsoButtonStyle.msoButtonCaption;
}
this.toolbarButton.Tag = "Hello Button";
this.toolbarButton.OnAction = "!<MyAddin1.Connect>";
this.toolbarButton.Visible = true;
this.toolbarButton.Click += new
Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.OnToolbarButtonClick);
}

/// <summary>
/// Implements the OnBeginShutdown method of the
IDTExtensibility2 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='IDTExtensibility2' />
public void OnBeginShutdown(ref System.Array custom)
{
this.toolbarButton.Delete(System.Reflection.Missing.Value);
this.toolbarButton = null;
}

private void OnToolbarButtonClick(CommandBarButton cmdBarbutton,ref
bool cancel)
{
System.Windows.Forms.MessageBox.Show("Hello World","My Addin");
}


}
}
 
Back
Top