TheSwamp

Code Red => .NET => Topic started by: Jeff_M on May 15, 2016, 12:22:07 PM

Title: Switch between Icon only .resx files
Post by: Jeff_M on May 15, 2016, 12:22:07 PM
I'm attempting (not very well at the moment) to get my project's Ribbon icons to correctly update based on the current theme in AutoCAD...light vs dark. I understand how this is done when using a CUIx to define the commands and ribbons items. However, we create our ribbon in code and I do not want to have to do something like this:
Code - C#: [Select]
  1. //in my Initialization code
  2. public static bool darkTheme = (Application.GetVariable("COLORTHEME") == 0);
  3.  
  4. //then set that as needed in a SystemeVariableChanged event handler.
  5. //all images are in the same Resource file
  6. //And then in my ribbon button code this:
  7.             rb = new RibbonButton();
  8.             rb.Image = darkTheme ? MyApp.flattenobjects_small.ToBitmapImageFromPng() : MyApp.flattenobjects_small_light.ToBitmapImageFromPng();
  9.             rb.LargeImage = darkTheme ? MyApp.flattenobjects.ToBitmapImageFromPng() : MyApp.flattenobjects_light.ToBitmapImageFromPng();
  10.  

On the surface this looks workable, except there are 200+ buttons with more being added. I would far prefer to do something like so:
Code - C#: [Select]
  1. //have 2 resource files, MyAppDark.resx and MyAppLight.resx, where the icons have the same names, but are the different icons.
  2. //have a MyApp variable which can be set to the correct one to reference in the SystemeVariableChanged event handler
  3. if(Application.GetVariable("COLORTHEME") == 0
  4.    MyApp = MyAppDark;
  5. else
  6.    MyApp = MyAppLight;
  7.  
  8. //then my ribbon buttons can simply be:
  9.             rb = new RibbonButton();
  10.             rb.Image = MyApp.flattenobjects_small.ToBitmapImageFromPng();
  11.             rb.LargeImage = MyApp.flattenobjects.ToBitmapImageFromPng();
  12.  

Where I'm stumped is at what I need to initialize MyApp as...can I simply do this?:
public static object MyApp = MyAppDark;

If so, I'm at a loss as to how to do so, because that doesn't work...
Title: Re: Switch between Icon only .resx files
Post by: Keith Brown on May 15, 2016, 02:31:09 PM
Jeff, I really think there was an article on this on the official boards that pointed to a blog post and to a swamp page.  I don't have it now but will look it up and share later.  I'm mobile right now.
Title: Re: Switch between Icon only .resx files
Post by: Jeff_M on May 15, 2016, 03:25:29 PM
Thanks, Keith. I did find a few blog posts, including one that pointed back to the Swamp, but they all deal with the CUIx approach. I want to avoid using the CUIx due to the inability to enable/disable ribbon buttons on the fly. We use this method to allow/disallow use of buttons depending on which module was purchased. It worked well until the dual color theme was introduced.
Title: Re: Switch between Icon only .resx files
Post by: BlackBox on May 15, 2016, 06:19:07 PM
Thanks, Keith. I did find a few blog posts, including one that pointed back to the Swamp, but they all deal with the CUIx approach. I want to avoid using the CUIx due to the inability to enable/disable ribbon buttons on the fly. We use this method to allow/disallow use of buttons depending on which module was purchased. It worked well until the dual color theme was introduced.

Creating a complete CUIx, or a CUIx for each module aside (admittedly a loaded task) - why can't you 'enable/disable buttons on the fly'?

If you create the CUIx, you assign the necessary Ribbon ID(s), and can then find the necessary RibbonButton and disable, no?

Cheers
Title: Re: Switch between Icon only .resx files
Post by: Bobby C. Jones on May 17, 2016, 12:10:51 PM
Where I'm stumped is at what I need to initialize MyApp as...can I simply do this?:
public static object MyApp = MyAppDark;

If so, I'm at a loss as to how to do so, because that doesn't work...

If MyAppDark and MyAppLight implemented a common interface, or inherited from the same base class, or both, then you'd declare the MyApp variable as that interface or base type.