Icons

There are a large number of built-in icons which you can use or you can design and use your own.


Built-in Icons

If you are using the Ribbon Designer you need to change the OfficeImageId property.
SS
If you are using a Ribbon.xml file and want a built-in image you can use the "imageMso" element.

<button id="Button1" imageMso="HappyFace" /> 

Custom Icons

If you are using the Ribbon Designer you need to add your custom icons to your solution, and reference them on the controls using the Image property.
If you are using a Ribbon.xml file you need to include the loadImage="Ribbon_LoadImage" at the top of your XML file.

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load" loadImage="Ribbon_LoadImage"> 
  <ribbon>

Create your custom icons and add them to the project resources.
SS
Instead of the "imageMso" element you need to use the "image" element.
The name of your image needs to correspond exactly with the name of the image in your resources.

<button id="Button1" image="Resource_Name" /> 

Add the following code to the bottom of your Ribbon.cs file.

public object Ribbon_LoadImage(string resourceName) 
{
    System.Drawing.Bitmap bitmap = (System.Drawing.Bitmap)Properties.Resources.ResourceManager.GetObject(resourceName);

    return (stdole.IPictureDisp)System.Windows.Forms.AxHost.GetIPictureDispFromPicture(bitmap);
}

Click the Resources tab and click Add Existing File from the add resource drop-down
Navigate to the bmp file and add it to your project
In the solution explorer select the bmp and set the Build property to Embedded Resource.


Add the following code to the end of the Ribbon1.vb file after End Class
This action adds a new class to your project that converts bitmaps to a picture type (IPictureDisp) that the Ribbon understands


Public Class BitmapToIPicture Inherits System.Windows.Forms.AxHost 
   Public Sub New()
       MyBase.New(Nothing)
   End Sub

   Public Shared Function Convert(ByVal Image as System.Drawing.Image) as stdole.IPictureDisp
      Convert = GetIPictureDispFromPicture(Image)
   End Function

End Class


Add the following code to the Ribbon1.vb class after the GetCustomUI function

Public Function GetImage(ByVal control as Office.IRibbonControl) as stdole.IPictureDisp 
   Return BitmapToIPicture.Convert(My.Resources.NAME)
End Function

In the XML file < getimage = "GetImage" />

public System.Drawing.Bitmap GetImage (Office.IRibbonControl control) 
{
   return new System.Drawing.Bitmap (Properties.Resources.MyIcon);
}

The image attribute is used when you want to provide a custom image for your controls
For document-level solutions these are usually contained inside the actual document.
The Ribbon drawing engine is designed to work with full-colour (24 bit) images that also have an alpha channel for pixel transparency


When Excel loads a workbook, it calls the loadimage callback for every image attribute it finds that doesn't point to an image contained within the file, passing the value of the image attribute as the imageID.
loadPicture does not handle the png file format




© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext