none
Microsoft Word 2010 Custom Add-In Icon RRS feed

  • Question

  • I just ported an older version of a word 2003 add-in (VS 2008) application to a word 2010 (VS 2013) add-in application .

    My question involves how to a custom icon to the ribbon add-in.

    Our previous code was created in an add-in code file that looked like this:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.DocumentBeforeSave += new Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(Application_DocumentBeforeSave);
    
                try
                {
                    cmdBar = Application.CommandBars["SAP Toolbox"];
                }
                catch (ArgumentException) { }
    
                if (cmdBar == null)
                {
                    cmdBar = Application.CommandBars.Add("SAP Toolbox", missing, missing, true);
                }
    
                cmdOpenToolbox = (Office.CommandBarButton)cmdBar.Controls.Add(Office.MsoControlType.msoControlButton, 1, missing, missing, true);
                cmdOpenToolbox.Caption = "Open SAP Toolbox";
    
                string CLSID = (string)Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\SAPToolbox\CLSID").GetValue("");
                string installpath = (string)Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\CLSID\" + CLSID + @"\InprocServer32").GetValue("ManifestLocation");
                string iconfile = installpath + @"\TOOLS.bmp";
                string maskfile = installpath + @"\MASK.bmp";
    
                if (File.Exists(iconfile)) {
                    System.Drawing.Image buttonImage = System.Drawing.Image.FromFile(iconfile);
                    System.Drawing.Image buttonMask = System.Drawing.Image.FromFile(maskfile);
                    cmdOpenToolbox.Picture = PictureDispConverter.ToIPictureDisp(buttonImage);
                    cmdOpenToolbox.Mask = PictureDispConverter.ToIPictureDisp(buttonMask);
                }
    
                cmdOpenToolbox.Tag = "Open SAP Toolbox";
                cmdOpenToolbox.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption;
                cmdOpenToolbox.Click += new Office._CommandBarButtonEvents_ClickEventHandler(doOpenToolbox);
                cmdBar.Position = Microsoft.Office.Core.MsoBarPosition.msoBarTop;
                cmdBar.Visible = true;
            }

    After searching for quite some time, I've not been able to find something similar to what I am looking for so I decided to post here.

    I ported this code over to my new project and everything builds fine and works, however the icon that our code is using is showing up too small, where I would like to display similar to the draft icon shown below:

    Can anyone point me to a proper walkthrough for something like this?

    Thanks.


    Tuesday, April 1, 2014 7:51 PM

Answers

All replies