Ribbon panel button image not displaying

Ribbon panel button image not displaying

sensiblehira
Advocate Advocate
897 Views
11 Replies
Message 1 of 12

Ribbon panel button image not displaying

sensiblehira
Advocate
Advocate

Hi I am trying to create my first ribbon button here. Every thing works fine but I cannot get my ribbon image to show as seen in the image

sensiblehira_0-1666968339268.png

please guide me with what could I be doing wrong.

0 Likes
Accepted solutions (1)
898 Views
11 Replies
Replies (11)
Message 2 of 12

corinne.astori
Advocate
Advocate

Can you show your code, where you set the image? What image format are you using?

0 Likes
Message 3 of 12

sensiblehira
Advocate
Advocate
public Result OnStartup(UIControlledApplication application)
        {
            RibbonPanel panel = RibbonPanel(application);
            string thisAssemblyPath = Assembly.GetExecutingAssembly().Location;
            if(panel.AddItem(new PushButtonData("Room Properties","Room Properties",thisAssemblyPath,"Room_Properties.Command1")) is PushButton button)
            {
                button.ToolTip="Set Unit Targets";
                Uri uri = new Uri(Path.Combine(Path.GetDirectoryName(thisAssemblyPath), "Resources", "SetUnitTargets.ico"));
                BitmapImage bitmap = new BitmapImage(uri);
                button.LargeImage = bitmap;
           
            }
            return Result.Succeeded;
        }
0 Likes
Message 4 of 12

sensiblehira
Advocate
Advocate

I think I cannot get the image files to get copied to AddIn folder

0 Likes
Message 5 of 12

corinne.astori
Advocate
Advocate

Try something like this:

myPushButton.LargeImage = GetIcon(myIcon);

 

Here the method to get the BitmapSource:

private static BitmapSource GetIcon(Icon icon)

{ return Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); }

 

I hope this helps.

KR,

Corinne

0 Likes
Message 6 of 12

corinne.astori
Advocate
Advocate

I usually add it to the resources of the project and then refer to it as follow:

myPushButton.LargeImage = GetIcon(MyProject.Properties.Resources.MyIcon);

0 Likes
Message 7 of 12

sensiblehira
Advocate
Advocate

I am getting error from the class Icon what reference has to be added for this. I am currently just following the beginner tutorials so I am confused by your answer. Hope you don't mind explaining

0 Likes
Message 8 of 12

corinne.astori
Advocate
Advocate

For the Icon class, You need to add a reference to System.Drawing (add using System.Drawing at the top).

0 Likes
Message 9 of 12

sensiblehira
Advocate
Advocate

is it from System.Drawing.Icon?

plus I am getting error for the later Image as well

0 Likes
Message 10 of 12

corinne.astori
Advocate
Advocate
Yes the Icon class is in System.Drawing.
What error are you getting?
Can you post your current code?
I am sorry if I confused you more than anything else, just trying to help...
0 Likes
Message 11 of 12

sensiblehira
Advocate
Advocate
Accepted solution

I managed to get the image to show on the panel, thanks for your help. turns out had some issue with the image itself

Message 12 of 12

sensiblehira
Advocate
Advocate

thanks for your help

0 Likes