MapInfo Pro Developers User Group

 View Only
Expand all | Collapse all

Can I also use my own custom icons/images for the controls?

Peter Møller

Peter Møller03-16-2018 08:20

Robin Morrison

Robin Morrison03-16-2018 09:18

  • 1.  Can I also use my own custom icons/images for the controls?

    Employee
    Posted 10-26-2017 10:45

    I have a number of icons that I would like to use for my custom controls. Is that possible?



  • 2.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 10-26-2017 07:00

    Yes, besides using the built-in icons of MapInfo Pro you can also reference your own custom icons, either as individual image files or inside a .NET assembly.

    MapInfo Built-in icons

    In the ConnectTheDots sample application I showed how to use built-in icons:

    Call SetRbnBtnCtrlSmallIcon(mtsBtnTool, New_Uri("pack://application:,,,/MapInfo.StyleResources;component/Images/Spatial/segmenting_16x16.png", 0))

    I have highlighted the specific part of the statemen that is specific to using built-in icons

    Image files

    Image files can be references in a very similar way where you basically replace the pack string with the file path to the image file:

    Call SetRbnBtnCtrlSmallIcon(mtsBtnTool, New_Uri(ApplicationDirectory$() & "Images\ & "MapWindowExcel_32.png", 0))

    You can use ApplicationDirectory$() to point at the current location of the application if that's where the images are located:

    Resources in a .NET assembly

    For a custom .NET assembly with icon resources, you need to modfify the Pack string to use addinorigon and specify the full path to the assembly and the name of the resoruce in the assembly

    Call SetRbnBtnCtrlSmallIcon(mtsBtnTool, New_Uri("pack://addinorigin:,,,/D:/folder/CustomResource.dll;component/Images/testImage.png", 0))

    Classic MapInfo Pro 32 bit icons

    For v17.0 we will also support the classic icons that you might remember from the 32 bit versions of MapInfo Pro.

    You will be able to use the icon constants from Icons.def as part of the reference to these icons.



  • 3.  RE: Can I also use my own custom icons/images for the controls?

    Posted 10-31-2017 19:21

    I am running Mapinfo Pro v 16.0.1 and Mapbasic 16.0.

    I can load a bmp as a button under the Table tab, Selection button group and all works fine. But when trying to use a .dll it fails to find the image.

    Visual studio gives the path to the image with the .dll as;

    E:\Mapbasic\rsIcon\rsIcon\Resources\recordselicon.bmp

    The first 'rsIcon' is the dll so should translate as;

    New_Uri("pack://addinorigin:,,,/E:/Mapbasic/rsIcon.dll;component/rsIcon/Resources/recordselicon.bmp", 0))

    But I get a "Cannot find resource" error. It finds the dll but not the image. I have tried a number of configurations of the path after the 'component' part but cannot get it to work. What am I missing?



  • 4.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 11-01-2017 04:21

    Toby,

    Have you tried using backslashes in the path to the dll as well, like:

    New_Uri("pack://addinorigin:,,,/E:\Mapbasic\rsIcon.dll;component/rsIcon/Resources/recordselicon.bmp", 0))

    If you still can't make it work, can you share your DLL?



  • 5.  RE: Can I also use my own custom icons/images for the controls?

    Posted 11-01-2017 18:02
      |   view attached

    Peter, Still no luck, so I have attached the .dll. I am wondering whether it has something to do with how I created it or the Visual Studio (2010) settings?

    Attachment(s)

    zip
    rsIcon.zip   13 KB 1 version


  • 6.  RE: Can I also use my own custom icons/images for the controls?

    Posted 11-01-2017 23:58
      |   view attached

    Actually, using a decompiler it doesn't look like the images are embedded in the .dll. I have attached another dll which contain the images but suffer the same error.

    Attachment(s)

    zip
    rsIcon_vs15.zip   8 KB 1 version


  • 7.  RE: Can I also use my own custom icons/images for the controls?

    Posted 11-03-2017 06:51

    Perhaps the DLL was created by a 32 bit application, and loading the DLL fails in 64 bit MapInfo?



  • 8.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 11-03-2017 06:55

    I was just going to ask a similar question, Hans 😎

    Was the assembly compiled into 32 bit, 64 bit or AnyCPU assembly?



  • 9.  RE: Can I also use my own custom icons/images for the controls?

    Posted 11-05-2017 19:59
      |   view attached

    It was compiled to Any. I have recompiled to x64 only and am still getting the error. I have attached the new dll and screenshots showing the compile/de-compile info. Might be a daft question, but are there case sensitivities??

    Attachment(s)

    zip
    rsIcon_vs15.zip   8 KB 1 version


  • 10.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 11-17-2017 02:29

    Toby,

    Sorry for the long delay.

    Are you sure your assembly contains an icon? I tried looking into it with Resource hacker and I couldn't see any image resources? I haven't used Resource hacker much with .NET assemblies so I might be mistaken though.

    I'll try to get a .NET assembly created of my own and do some testing.



  • 11.  RE: Can I also use my own custom icons/images for the controls?

    Posted 11-19-2017 19:03

    Peter, The rsIcon_vs15.dll contains ?two bmp's within 'Resources'. A large one named rsIcon_vs15.recordselicon.bmp and a small one called rsIcon_vs15.recordseliconsmall.bmp. I used JetBrains dotPeek 2017.2.2 to view the contents of the .dll



  • 12.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 12-22-2017 05:36

    Hi @Toby Grant?,

    Finally, I were able to get mine to work.

    First of all make sure that when you select your images in Visual Studio that the Build Action has been set to Resource and that Copy to Output Directory has been set to Do not copy.

    Resource Settings

    We also had some issues with paths that had spaces in them. This has been fixed in the upcoming release and will also be (or maybe it's already) fixed in the beta release of MapInfo Pro 17.0.

    The workaround for paths with spaces is to use the "file:///" schema when referring to assemblies, like this:

    Call SetRbnBtnCtrlLargeIcon(mtsBtn, New_Uri("pack://addinorigin:,,,/file:///" + ApplicationDirectory$() + "ImageResource.dll;component/Resources/First32x32.png", 0))

    I have attached my small sample assembly which holds the above mentioned image.

    If you are using an older version of MapInfo Pro and do not have spaces in the path, you ought to be able to use this url with the file:/// schema:

    Call SetRbnBtnCtrlLargeIcon(mtsBtn, New_Uri("pack://addinorigin:,,,/" + ApplicationDirectory$() + "ImageResource.dll;component/Resources/First32x32.png", 0))

    Let me know how you get along

    Attachment(s)

    zip
    ImageResource.zip   2 KB 1 version


  • 13.  RE: Can I also use my own custom icons/images for the controls?

    Posted 02-04-2018 22:49

    Hello Peter,

    It worked! Thank you. I wasted a lot of time fiddling with the VS compile options so will have to improve my skills there in future.



  • 14.  RE: Can I also use my own custom icons/images for the controls?

    Posted 03-13-2018 07:19

    Hi Peter,

    I am having similar issues using custom icons. I downloaded your ImageResource.dll to my c:\temp folder and I've tried some of the uri s in this thread but I cant get the images to appear. What is the uri for your small and large icon?

    Thanks

     

     



  • 15.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 03-15-2018 06:52
    Hi Robin You can see my uri in the post above. Otherwise try posting your uri here and I’ll take a look


  • 16.  RE: Can I also use my own custom icons/images for the controls?

    Posted 03-16-2018 04:53
      |   view attached

    Hi Peter,

     

    I am trying this out in the RibbonCutomizationAddIn Sample that comes with MapBasic16. Here are my lines of code:

             Call SetRbnGalleryItemLargeIcon(endProgram, new_Uri("pack://addinorigin:,,,/file:///" + ApplicationDirectory$() + "ImageResource.dll;component/Resources/First32x32.png", 0))

                Call SetRbnGalleryItemSmallIcon(endProgram, new_Uri("pack://addinorigin:,,,/file:///" + ApplicationDirectory$() + "ImageResource.dll;component/Resources/First16x16.png", 0))

    I retried this morning and got the attached error.

     

     



  • 17.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 03-16-2018 06:36

    Have you tried placing the ImageResource.dll in the same folder as your application?



  • 18.  RE: Can I also use my own custom icons/images for the controls?

    Posted 03-16-2018 07:07

    Yes I have tried this, the path is:

     

    C:\VSProj\Samples\RIBBONINTERFACE\MapBasic\RibbonCustomization

     

    No spaces or strange characters.



  • 19.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 03-16-2018 08:20
    And you have at least 16.0.1?


  • 20.  RE: Can I also use my own custom icons/images for the controls?

    Posted 03-16-2018 09:18

    Yes 16.0.3.



  • 21.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 03-26-2018 03:11

    Robin,

    Have you tried using the URI without "file:///":

    Call SetRbnBtnCtrlLargeIcon(mtsBtn, New_Uri("pack://addinorigin:,,,/" + ApplicationDirectory$() + "ImageResource.dll;component/Resources/First32x32.png", 0))



  • 22.  RE: Can I also use my own custom icons/images for the controls?

    Posted 03-26-2018 10:57

    Hi Peter,

     

    I've tried without and I still get the same error, tried removing applicationdirectory$ and hard coding the path, still the same error.



  • 23.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 05-01-2018 02:55

    Sorry Robin, I got distracted.

    I have seen a similar error just now with another assembly. I'll try to look into this.



  • 24.  RE: Can I also use my own custom icons/images for the controls?

    Posted 05-01-2018 03:26

    Hi Peter,

    Thanks for this - I got distracted also!



  • 25.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 05-01-2018 03:29

    I upgraded my MapInfo Pro 16.0.2 to 16.0.3 and now I can load the assemblies if the URI used also holds the "file:///" element.

    This is only necessary for paths with spaces but as you never know where people will install your application, I would recommend always to include file:///.



  • 26.  RE: Can I also use my own custom icons/images for the controls?

    Posted 06-27-2018 05:19

    It has been as long time but just in case this is a problem for others, we have finally got it working - were were calling the Gallery Item control procedure

    Call SetRbnGalleryItemLargeIcon

    which doenst work, but when we used the button procedure:

    Call SetRbnBtnCtrlLargeIcon

    All works OK.

    Would you be able to check the Gallery Item procedure to see if it works for you?

    Many thanks

     



  • 27.  RE: Can I also use my own custom icons/images for the controls?

    Employee
    Posted 06-27-2018 09:02

    Hi Robin

    With MapInfo Pro 17, I were able to use these statements to assign a custom icons to a Gallery Element:

    Call SetRbnGalleryItemSmallIcon(TableGallItem1, New_Uri("pack://addinorigin:,,,/file:///" + ApplicationDirectory$() + "ImageResource.dll;component/Resources/First32x32.png", 0))

    Call SetRbnGalleryItemLargeIcon(TableGallItem1, New_Uri("pack://addinorigin:,,,/file:///" + ApplicationDirectory$() + "ImageResource.dll;component/Resources/First32x32.png", 0))

    Were you using a similar statement?