Adding button images via custom dll on ribbon

353 views
Skip to first unread message

Hank Finley

unread,
Sep 1, 2016, 7:01:31 PM9/1/16
to MapInfo-L

Hi All,

 

I'm trying to add an image to a button on the ribbon.

 

I'm not sure if I have created this correctly, however, I have created a .Net dll with a bunch of png images as resources

 

This is the project structure:

BAResources

                Properties

                                Assembly.cs

                                Resources.resx

                References

                                ...

                Resources

                                Images

                                                ButtonImages

                                                                EditLarge.png

                                                                EditSmall.png

                                                                InfoLarge.png

                                                                InfoSmall.png

 

Now in the "Ribbon" MapBasic example it has the following code:

Call SetRbnBtnCtrlLargeIcon(button1, New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Mapping/openTable_32x32.png", 0))

 

This BAResources.dll will reside in the same directory as my mbx.

[Question 1]

How do I write my URI?

[Question 2]

Also for the new routine calls like SetRbnBtnCtrlLargeIcon(), where do I find the documentation, did a search in the MapBasic help and it didn't find anything?

 

Kind regards

Peter Horsbøll Møller

unread,
Sep 2, 2016, 6:33:00 AM9/2/16
to mapi...@googlegroups.com

Hi,

 

Let me start with the later question.

The documentation for the .NET API can be found in the ExtensibilityReferenceHelp.exe.

That’s a separate help file to the normal MapBasic Help file

 

Be aware that SetRbnBtnCtrlLargeIcon is the MapBasic name for a method in a .NET assembly.

So you need to locate this name in the MapInfoPro.def file, notice what class it refers to (here MapInfo.Types.IRibbonButtonControl) and then find the help for this class in the before mentioned Help file.

 

As for the images, I haven’t yet tried to create my own assemblies containing custom icons/images.

So I’m not entirely sure how to refer to the image.

 

Looking at the string for the built-in images, it could be something along this:

"pack://application:,,,/MapInfo.StyleResources;component/Images/Mapping/openTable_32x32.png"

 

"pack://application:,,,/someassemblyname;BAResources/Images/ ButtonImages/EditLarge.png.png"

 

But I haven’t tried it. Maybe this can be of more assistance:

http://stackoverflow.com/questions/22664534/how-to-make-uri-reference-to-a-resource-image-embedded-in-the-assembly-itself

 

So far I have just used images stored in a folder in my application directory.

 

Peter Horsbøll Møller

EMEA Channel Enablement Specialist

Location Intelligence | MapInfo

 

M: +45 29 133 769

peter....@pb.com | @phorsbollmoller

pitneybowes.com/dk | mapinfo.com

--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en

---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.




Hank Finley

unread,
Sep 7, 2016, 4:12:51 AM9/7/16
to MapInfo-L
Hi there,

still having issues with this one.

One thing I have figured out is that if the "BAResources.dll" is in the same directory as the mbx, you remove the commas, so it looks like the following: (Ignoring the path to the image 'Properties/Resources/LineAddSm.png' as that's still wrong)

Call SetRbnBtnCtrlSmallIcon(BA_Btn, New_Uri("pack://application:/BAResources;Properties/Resources/LineAddSm.png", 0))

I should mention that the way I built this dll was as a c# class library (with nothing in the class) and just added the resources.

Kind Regards H

Thomas Bacon

unread,
Sep 7, 2016, 6:34:09 AM9/7/16
to mapi...@googlegroups.com

Hi Hank,

 

I’ve never used a .NET library for resources so I’m no expert, but a few things you could try:

 

-          Check that your path is using the correct slash (forward or backward) – maybe just try both and see if either works?

-          Check whether the slashes in the path need an escape character to be read correctly? In C# the escape character is ‘\’

-          Check that you set the resources as Embedded Resources when creating the DLL – if not, they won’t be included in the assembly!

 

No guarantee any of these will work but these are the first things I would check.

 

HTH,

 

Tom



_________________________________________________________________________
This email is sent on behalf of Kier Group. This email and any attachments are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the addressee, please do not use or publish its contents, please notify Kier Group on +44 (0) 845 607 7000 immediately and then delete it. Contracts cannot be concluded with us nor services effected by email. Emails are not secure and may contain viruses, you are advised to scan all messages for viruses with your own anti-virus programme. Kier Group may monitor emails
_________________________________________________________________________

Hank Finley

unread,
Sep 7, 2016, 9:38:24 AM9/7/16
to MapInfo-l

Hi Tom,
If what you're saying about the slash being backwards is true, may mean all the MapBasic ribbon examples are wrong. This may be the case as I haven't been able to get the button images to work on these either.
Will have to try this in the morning as its midnight here.
Kind regards H

> This email is sent on behalf of Kier Group. This email and any attachments are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the addressee, please do not use or publish its contents, please notify Kier Group on +44 (0) 845 607 7000 immediately and then delete it. Contracts cannot be concluded with us nor services effected by email. Emails are not secure and may contain viruses, you are advised to scan all messages for viruses with your own anti-virus programme. Kier Group may monitor emails
> _________________________________________________________________________
>

Hank Finley

unread,
Sep 7, 2016, 10:34:40 PM9/7/16
to MapInfo-L
Oops might have been wrong about the Samples/MapBasic examples. Had been playing around the URIs.

Had some success with my dll. I created a class library, nothing in the class, added an "Images" folder under the root of the project, not under the resources. Added the images I wanted as regular files then changed their "Build" property to "Resource". Compiled and popped the BAResources.dll into the MapInfo Profession root folder.
I then used:
Call SetRbnBtnCtrlLargeIcon(BA_Btn, New_Uri("pack://application:,,,/BAResources;component/Images/BlankAddLg.png", 0))

Don't forget to use the following statement before you try to create any URI or else none of this will work:
Call RegisterUriParser(New_GenericUriParser(1), "pack", -1)

Anyway this worked and the button found the image.

Now trying to figure out how to construct the Uri so that it is relative to the mbx, which will reside in the same folder.

When your building a new_URI, does MapBasic have "Defines" for URI Kind's? All the examples are set to 0, which I'm guessing is UriKind.Absolute, what about UriKind.Relative or UriKind.AbsoluteOrRelative?

Kind regards H

> To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+unsubscribe@googlegroups.com.


> For more options, visit https://groups.google.com/d/optout.
>
>
>
> _________________________________________________________________________
> This email is sent on behalf of Kier Group. This email and any attachments are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the addressee, please do not use or publish its contents, please notify Kier Group on +44 (0) 845 607 7000 immediately and then delete it. Contracts cannot be concluded with us nor services effected by email. Emails are not secure and may contain viruses, you are advised to scan all messages for viruses with your own anti-virus programme. Kier Group may monitor emails
> _________________________________________________________________________
>
> --
> --
> You received this message because you are subscribed to the
> Google Groups "MapInfo-L" group.To post a message to this group, send
> email to mapi...@googlegroups.com
> To unsubscribe from this group, go to:
> http://groups.google.com/group/mapinfo-l/subscribe?hl=en
> For more options, information and links to MapInfo resources (searching
> archives, feature requests, to visit our Wiki, visit the Welcome page at
> http://groups.google.com/group/mapinfo-l?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups "MapInfo-L" group.

> To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+unsubscribe@googlegroups.com.

Cliff B

unread,
Apr 11, 2017, 1:12:38 AM4/11/17
to MapInfo-L
Hi Hank

I'm tackling this now and was wondering if you ever get this sorted.
I'm not getting an error thrown with my URI creation but the set icon is setting it to no image rather than the image referenced in the DLL

My mapbasic cmd is as follows:
call SetRbnToolBtnCtrlLargeIcon(NuggetPointSelectTool, New_Uri("pack://application:,,,BoundaryMakerMethods;component/images/Recycle.png", 0))

The dll is a .net class library with a bunch of images added as resources and have an access modifier as public.


Regards
Cliff

> _________________________________________________________________________
> This email is sent on behalf of Kier Group. This email and any attachments are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you are not the addressee, please do not use or publish its contents, please notify Kier Group on +44 (0) 845 607 7000 immediately and then delete it. Contracts cannot be concluded with us nor services effected by email. Emails are not secure and may contain viruses, you are advised to scan all messages for viruses with your own anti-virus programme. Kier Group may monitor emails
> _________________________________________________________________________
>
> --
> --
> You received this message because you are subscribed to the
> Google Groups "MapInfo-L" group.To post a message to this group, send
> email to mapi...@googlegroups.com
> To unsubscribe from this group, go to:
> http://groups.google.com/group/mapinfo-l/subscribe?hl=en
> For more options, information and links to MapInfo resources (searching
> archives, feature requests, to visit our Wiki, visit the Welcome page at
> http://groups.google.com/group/mapinfo-l?hl=en
>
> ---
> You received this message because you are subscribed to the Google Groups "MapInfo-L" group.

Uffe Kousgaard

unread,
Apr 11, 2017, 1:55:45 AM4/11/17
to mapi...@googlegroups.com
Hi,

Peter Møller wrote in an e-mail on 6th of Jan, that it should be possible after a patch for 16.0.
That must mean it is part of 16.0.1, but I haven't tested it.

Check his e-mail for syntax.

Regards
Uffe Kousgaard

Cliff B

unread,
Apr 12, 2017, 1:22:18 AM4/12/17
to MapInfo-L
I've found the Jan post  (https://groups.google.com/forum/#!topic/mapinfo-l/1rgB10z2-JE )

Using call SetRbnToolBtnCtrlLargeIcon(NuggetPointSelectTool, New_Uri("pack://addinorigin:,,,/BoundaryMakerMethods.dll;component/Images/Recycle", 0))
I'm now getting errors which is progress!

I'm pretty sure this is referencing my .Net dll as if I name it incorrectly is get an unable to load assembly error.

However I can't workout the format of the component section as I'm getting Cannot locate resource errors.

Failing this is there a way I can just create an "icon" directly from a bmp or png or something?

Peter Horsbøll Møller

unread,
Apr 12, 2017, 4:05:39 AM4/12/17
to mapi...@googlegroups.com

Cliff,

 

Make sure that you have a full path to the dll, for example by adding ApplicationDirectory$() to the path.

 

Also, here is an example of the naming of the built-in images:

"pack://application:,,,/MapInfo.StyleResources;component/Images/Application/closeAll_16x16.png"

Notice that it also has the filetype, but I assume that’s just the way the resource was named in the assembly.

 

You can always reference a file on disk using the same syntax but replacing the entire pack string with the path and file name:

Call SetRbnToolBtnCtrlLargeIcon(NuggetPointSelectTool, New_Uri(ApplicationDirectory$() & "NiceImage32.png", 0))

 

I found this more detailed description of the syntax:

"pack://addinorigin:,,,/{absolute path to resource assembly};component/{location of image in assembly with image name}"

example : "pack://addinorigin:,,,/D:/folder/CustomResource.dll;component/Images/testImage.png"

 


Peter Horsbøll Møller

Pitney Bowes

Cliff B

unread,
Apr 12, 2017, 8:11:29 PM4/12/17
to MapInfo-L
Hi Peter,

I've tried with the full dll path and without, and get the, same cannot locate resource error, and if I change the name of the DLL i get an unable to load assembly error, so I'm sure it's finding the DLL just not finding the images within it.
using ILSpy they are showing as BoundaryMakerMethods.Properties.Resources.Recycle, which I've tried variations of also with no luck.

However I've got the images loading directly so I'm going to go with that.

One issue I've come across is some of my images are loading and some are not, it seems like the small ones (18x16 pixels) are displaying but the larger icons aren't. The images not working are only 26x24 pixels which are smaller than the images in the default MapInfo Ribbon.
Are there image dimension or colour depth limits for the button large icons? If so, does anyone know what they are so I can scale my images appropriately?

Thanks
Cliff

Cliff B

unread,
Apr 12, 2017, 11:57:39 PM4/12/17
to MapInfo-L
After a little more digging, I think it may ben an issue with the DLL's I'm making as opening the Mapinfo.StyleResources dll in ILSpy, I can see all the images under the main resources tree where as my DLL has the buried under an additional class.

So I've got a little bit of work to do on how I've constructed my dll.

Thanks for the help though.

Deryck Brown

unread,
Nov 20, 2019, 9:54:17 AM11/20/19
to mapi...@googlegroups.com
Hi,

I've just been trying to get a custom image to appear on a ribbon button, and encountered a similar set of frustrations.

What I did find was this:

Your images should be resources in a Visual Studio project for a WPF Control library. It is sufficient to include the images files in a folder, e.g., "images", and set their build type to "resource". The "pack" URIs referencing the assembly name should use the "addinorigin:" format, specifying the full name of the DLL with ";component/images/filename.png" at the end.

Your DLL project needs to have a CPU type of x64 and, possibly, target .Net v4.6.1 (which seems to be the current version for MapInfo 17).

Also, image URIs do not work if the full pathname to the DLL has spaces in it. There seems to be some weird processing of the URI before being used to access the file that completely ruins it. I did manage to work round this by using GetShortPathName from "kernel32.dll" which returns the equivalent "8.3" path name, and using that to first convert ApplicationDirectory$() to a version without spaces.

Regards,
Deryck

Deryck Brown

unread,
Nov 21, 2019, 6:46:32 AM11/21/19
to MapInfo-L
Folks,

Ok just noticed the following in the documentation:

To reference a resource assembly located on a UNC share, or in a path that includes space(s), define the pack uri specifying the 'file:' scheme example : "pack://addinorigin:,,,/file://myshare/folder/CustomResource.dll;component/Images/testImage.png" example : "pack://addinorigin:,,,/file:///D:/folder/resource folder/CustomResource.dll;component/Images/testImage.png"

Given that the MapBasic programmer cannot control where a user may put the addin, and therefore whether or not the resulting location may be using a UNC path or have spaces in the name, it seems bizarre to have two different methods, one of which seems to be practically useless.

The next thing I've noticed, however, is that the "Tool Manager" does not appear to understand "pack://addinorigin:" URIs to select the tool icon for registered addins.

Deryck
Reply all
Reply to author
Forward
0 new messages