4 Replies Latest reply on Aug 28, 2014 11:43 PM by Seth Ruhan

    Changing Command Icons

    Seth Ruhan

      Hi,

       

      In an addin, its got several commands. However after creating the command is there a way to change the icon used?

       

      Similar to the rebuild icon some time changes to indicate a rebuild is required.

       

      I have though about removing the command and putting a 'new' one with a different icon in its place. However the idea of this command was to go on the main drag, where I belive you can only get icons there via registry edit, which I assume you carn't change dynamiclly.

       

      Any help would be awesome,

       

      Thanks

        • Re: Changing Command Icons
          Rajat Jain

          Hi,

           

          I think you can follow one of these approaches: -

          1. Create a toolbar bitmap with all possible command icons. Create the commandgroup with all commands and only show relevant commands. When you want to change the icon, simply hide one command and show the other (in comamndEnable event).
          2. Use CommandGroup::smallIconList and CommandGroup::LargeIconList to assign the new bitmap for the commandgroup.

           

          I hope it helps!!!

           

          Rajat Jain

            • Re: Changing Command Icons
              Seth Ruhan

              Hi Rajat,

               

              Are you suggesting two command items? (to use the rebuild example)

              1 Rebuild

              2 RebuildRequired (with warning sign)

               

              How do you hide a a commanditem? I know how to hide a tool bar, or control commandgroup visability per document type , or to disable a commandItem

               

              I have had issues when trying to load muliple Icon lists, have you seen similar issues? I ended up having alot of icons instead.

                • Re: Changing Command Icons
                  Rajat Jain

                  Hi,

                   

                  I have used the first approach to show/hide commands. But it was in context sensitive menu where there is an option to show/hide the command in the CommandEnable event function. I am not sure if this option exists for the Menu and Toolbar commands.

                   

                  I have not used the second approach myself but I see no issue. For instance, there are 2 bitmaps (each having 3 commands). The first 2 command icons are same in both the bitmaps and the third is different. If I update the ImageList, it should not result in many additional icons. I can check it (in some spare time at home tonight) and update you.

                   

                  I hope it helps!!!

                   

                  Rajat Jain

                • Re: Changing Command Icons
                  Seth Ruhan

                  Hi,

                   

                  After a lot of playing around, I can not get the icon to change, I can change the CreateCommandGroup2 icon lists, but this does not reflect the actual command item's image.

                  Any other idea's?

                  If System.Environment.UserName.ToUpper = "SETRUH" Then

                                  Try

                                      cmdGroup = iCmdMgr.CreateCommandGroup2(99, "Test title", "Test toolTip", "Hint", 5, ignorePrevious, cmdGroupErr)

                   

                   

                                      cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("OU_SW_SEAP_Addin.ToolbarLarge.bmp", thisAssembly)

                                      cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("OU_SW_SEAP_Addin.ToolbarSmall.bmp", thisAssembly)

                                      cmdGroup.LargeMainIcon = iBmp.CreateFileFromResourceBitmap("OU_SW_SEAP_Addin.AddinIcon.bmp", thisAssembly)

                                      cmdGroup.SmallMainIcon = iBmp.CreateFileFromResourceBitmap("OU_SW_SEAP_Addin.AddinIcon.bmp", thisAssembly)

                   

                                      TestButton = cmdGroup.AddCommandItem2("Test Button", -1, "test", "test", 0, ButtonClass.MethodName(AddressOf UI_Test), ButtonClass.MethodName(AddressOf IC_Test), mainItemID13, swCommandItemType_e.swMenuItem)

                   

                   

                                      cmdGroup.HasToolbar = True

                                      cmdGroup.HasMenu = True

                                      cmdGroup.Activate()

                                  Catch ex As Exception

                                      MsgBox("Test Error")

                                      LogWriter.WriteLog("Error Test01 :" & ex.Message)

                                      LogWriter.WriteLog("Stack : " & ex.StackTrace)

                                  End Try

                              End If

                  Dim Test As Integer = 1

                      Sub UI_Test()

                          Dim cmdGroup As ICommandGroup = iCmdMgr.GetCommandGroup(99)

                          Dim thisAssembly As Assembly = System.Reflection.Assembly.GetAssembly(Me.GetType())

                          MsgBox(cmdGroup.LargeIconList)

                          If Test = 1 Then

                              Test = 0

                              cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("OU_SW_SEAP_Addin.AddinIcon.bmp", thisAssembly)

                              cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("OU_SW_SEAP_Addin.AddinIcon.bmp", thisAssembly)

                          Else

                              Test = 1

                              cmdGroup.LargeIconList = iBmp.CreateFileFromResourceBitmap("OU_SW_SEAP_Addin.ToolbarLarge.bmp", thisAssembly)

                              cmdGroup.SmallIconList = iBmp.CreateFileFromResourceBitmap("OU_SW_SEAP_Addin.ToolbarSmall.bmp", thisAssembly)

                          End If

                          MsgBox("Pushed")

                      End Sub