-
December 9th, 2010, 08:21 AM
#1
How to include a image as a button in Outlook?
Hi @ll,
Basically i am a learning java programmer. i happened to work on an Outlook application, to create a Outlook Toolbar, for which i preferred C#(as this is more similar to java) and now i am using Google to learn it. The problem started when i thought to use a image for a button. I can't figure out where it is going wrong;........
Code:
MyPictureHost.GetIPictureDispFromPicture(Image.FromStream(imgageStream));
This line is showing an error as,
Cannot implicitly convert type 'object' to 'stdole.IPictureDisp'.An explicit conversion exists(are u missing a cast?)
Complete code is below:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using RefAssembly = System.Reflection.Assembly;
using Office = Microsoft.Office.Core;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Drawing;
namespace OutlookAddIn2
{
public partial class ThisAddIn : MyPictureHost
{
Outlook.Explorers myExplorers = null;
Office.CommandBar myCommandBar = null;
Office.CommandBarButton myCommandBarButton = null;
Office.CommandBarButton myCommandBarButton2 = null;
String COMMANDBAR_NAME = "MyHome";
void Explorers_NewExplorer(Microsoft.Office.Interop.Outlook.Explorer Explorer)
{
((Outlook.ExplorerEvents_10_Event)Explorer).Activate += new Microsoft.Office.Interop.Outlook.ExplorerEvents_10_ActivateEventHandler(ThisAddIn_Activate);
LoadToolBar();
}
void ThisAddIn_Activate()
{
LoadToolBar();
}
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
myExplorers = this.Application.Explorers;
myExplorers.NewExplorer += new Microsoft.Office.Interop.Outlook.ExplorersEvents_NewExplorerEventHandler(Explorers_NewExplorer);
if (this.Application.Explorers.Count > 0)
{
LoadToolBar();
}
}
private void LoadToolBar()
{
try
{
foreach (Office.CommandBar bar in this.Application.ActiveExplorer().CommandBars)
{
if (bar.Name.Equals("Test"))
{
myCommandBar = bar;
break;
}
}
if (myCommandBar == null)
{
myCommandBar = this.Application.ActiveExplorer().CommandBars.Add(COMMANDBAR_NAME, missing, missing, true);
myCommandBar.Protection = Office.MsoBarProtection.msoBarNoProtection;
myCommandBar.Position = Microsoft.Office.Core.MsoBarPosition.msoBarTop;
myCommandBar.Left = 0;
myCommandBar.RowIndex = 1;
Office.CommandBarControl myCommandBarControl = myCommandBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, true);
myCommandBarControl.Caption = "MyHome";
myCommandBarButton = ((Office.CommandBarPopup)myCommandBarControl).CommandBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, "", 1, true) as Office.CommandBarButton;
myCommandBarButton2 = myCommandBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, "", 1, true) as Office.CommandBarButton;
myCommandBarButton.Caption = "Campaign";
myCommandBarButton2.Caption = "about";
RefAssembly ThisAssembly = RefAssembly.GetExecutingAssembly();
System.IO.Stream imgageStream = ThisAssembly.GetManifestResourceStream("OutlookAddIn2.Resources.go.bmp");
myCommandBarButton.Picture = MyPictureHost.GetIPictureDispFromPicture(Image.FromStream(imgageStream));
myCommandBarButton.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(myCommandBarButton_Click);
}
myCommandBar.Visible = true;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show("Error while Loading Toolbar : " + ex.Message + "\n" + ex.StackTrace);
}
}
void myCommandBarButton_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
{
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
#region VSTO generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InternalStartup()
{
this.Startup += new System.EventHandler(ThisAddIn_Startup);
this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
}
#endregion
}
}
Please any one help me to get rid of this
Thanks in Advance
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|