CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010
    Posts
    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

  2. #2
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: How to include a image as a button in Outlook?

    did you see How to: Add Custom Icons to Toolbar and Menu Items ? see number 2. there is a sample class to convert the image.
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured