Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Shared Resource Icons accross Assemblies on the Ribbon?
posted

I have a situation that I can just not seem to find a work around for and would appreciate some help.  

I would like to consolidate all of my icons used across a solution into a single place such that I can update them and after a recompile have all the ribbon controls within my solution are "auto-updated".  This of course is for long term maintainability, if I want to swap an icon I dont have to touch every single ribbon. 

The problem in large is that I can not find a clever way for a instance of UltraToolsbarManager to look at a resource that lives beyond its own assembly.  Things I have tried:

- Inherit from ImageList to create my own filled controls and associate the large and small image lists with the toolbar (Doesnt work because ImageList is sealed)

- Inherit from a base form that contains exposed ImageList controls (Doesnt work because the inheriting form copies the parents icons into its own .resx file and never looks at it again)

- Create a resource only assembly (Doesnt work because the designer only recognizes resources local to its own assembly)

- Create a solution level resource file and "link" the file into each assembly - much like the central AssemblyInfo.cs trick (Had a little promise but then the solution always gets in this weird chicken and egg scenario and wont build after cleans).

- Programmatically set the small and large image lists from a factory pattern icon class (Works but you lose all design time support)

 

This leaves me only will two options that I can see:

- Programmatically set all the icons by hand (this is super gross and I am not doing this)

- Simply select each icon file, allow the Ribbon control and VS.NET to do what it does during design time [that is slurp the file into the form level resx file] but have the possible long term maintaince headache of manually changing icons.

 

Does anybody have a trick for this?  Does anyone from Infragistics have a recommendation or particular stance?  

Any help is greatly appreciated...

Thanks, -Max 

  • 280
    posted

    Max

    I've just done something a bit like this myself.

    My first idea was, like you, to inherit from the ImageList. In the end, I got around it by creating a shared function that would populate an Imagelist and return it.

    First, I created a resource file in my Class Library for each of my icon sets (so for example: a resource file for file/disk icons).

    Then I created the following shared function:

        Public Shared Sub LoadIcons(ByVal ImageList As System.Windows.Forms.ImageList, ByVal Type As IconsTypeEnum)

            Dim ResMgr As Resources.ResourceManager

            Select Case Type
                Case IconsTypeEnum.ProjectAction
                    ResMgr = My.Resources.ProjectAction.ResourceManager
                Case IconsTypeEnum.TrafficLights
                    ResMgr = My.Resources.TrafficLights.ResourceManager
                Case Else
                    ResMgr = Nothing
            End Select

            If Not ResMgr Is Nothing Then
                Dim Res As Resources.ResourceSet = ResMgr.GetResourceSet(My.Application.Culture, True, True)
                Dim ResEnum As IDictionaryEnumerator = Res.GetEnumerator

                While ResEnum.MoveNext
                    ImageList.Images.Add(ResEnum.Key, ResEnum.Value)
                End While
            End If

        End Sub

    Basically, you pass the function an enumeration which decides what type of icons you want, then it loops through the appropriate resource file and populates the listview with icons.

    Finally, in your Windows form, add a listview control, and in the Form_Load call this function to populate it with icons at runtime.

     

    Hope that helps

     

    Chris