Not sure if you got the answer you were looking for. Here's a step-by-step to create a resource dll
- Create a new project in visual studio, class library
- Add your resources (pictures) to the project (Add existing item)
- For each resource, in the properties window, set Build Action to Embedded resource
- Compile the library, produces a dll
- In your winforms application, you can now load this assembly at runtime (Code #1)
- Load the resource stream that you want and save it to a Bitmap object (Code #2)
Code #1
Assembly ambly = Assembly.LoadFile(pathToDll);
Code #2
BitMap bitMap;
// where "ns" is the default namespace of the resource project
using (Stream resourceStream = ambly.GetManifestResourceSream("ns.image.jpg"))
{
bitMap = BitMap.FromStream(resourceStream);
}
These are the basic techniques used for embedding resources and loading them at runtime.
Now, since you're thinking of having different themes, and store the resources for each theme in different libraries, you should have an interface that specifies some sort of resource manager, defined in your main application.
An example
interface IThemeResourceProvider
{
Stream LoadBigLogo();
Stream LoadSmallLogo();
}
Then implement that interface in your resource library
public class ThemeResourceProvider : IThemeResourceProvider
{
public Stream LoadBigLogo()
{
Assembly ambly = Assembly.GetExecutingAssembly();
return ambly.GetManifestResourceStream("namespace.image.jpg");
}
(...)
}
Finally, instead of loading the resource directly in your main application, you instantiate the IThemeResourceProvider found in the resource library
Assembly assembly = Assembly.LoadFile(pathToDll);
var results = from type in assembly.GetTypes()
where typeof(IThemeResourceProvider).IsAssignableFrom(type)
select type;
Now you have an IEnumerable<Type>
in that list. Typically, you'd only have one, but using this approach you could also host multiple sets of resources, and implement multiple IThemeResourceProviders in the same resource dll. You could e.g. identify each IThemeResourceProvider with a name, either as a property, or using a custom [Attribute]
decoration on your various implementations. I'll leave the rest up to you to figure out.
But here's how to instantiate the IThemeResourceProviders in your list
foreach (var providerType in results)
{
var constructorInfo = providerType.GetConstructor(Type.EmptyTypes);
IThemeResourceProvider provider = constructorInfo.Invoke(null);
}
And finally, using one of these providers to get a bitmap:
BitMap bitMap;
using (Stream resourceStream = provider.LoadBigLogo())
{
bitMap = BitMap.FromStream(resourceStream);
}