Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Experts ,
I want to make DLL That Contains Only Resources , And How Can I use It?
How Can Get Resources In Different Situation In c# Windows Form Code ,
Thanks all
Posted

Hi,

Yes, it's possible to do that. Create a new project (Class Library), and add resources to it. The Resources class is an internal class, so you can't use it in another project. So, add a static class in your Class Library projects, GetResources:
C#
public static class GetResources
{
      public static object GetObject(string name)
      {
           return Properties.Resources.ResourceManager.GetObject(name);
      }
      public static string GetString(string name)
      {
           return Properties.Resources.ResourceManager.GetString(name);
      }
      public static System.Resources.ResourceManager GetResourceManager()
      {
           return Properties.Resources.ResourceManager;
      }
}

And in your other project, add a reference to this Class Library. To get the value of the string "String1" in the resources of your Class Library, you can use this code:
C#
string string1 = GetResources.GetString("String1");

To get an image "Image1", use this code:
C#
Bitmap bmp = GetResources.GetObject("Image1") as Bitmap;

Hope this helps.
 
Share this answer
 
I would strongly advise to add the code exposing those resources, for proper encapsulated approach.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900