How can I access embedded resources in a C# project?

前端 未结 2 1804
粉色の甜心
粉色の甜心 2020-12-11 05:52

Most of the threads I\'ve read about this question answer that you just have to access them like this:

.Properties.Resources.

        
相关标签:
2条回答
  • 2020-12-11 06:21

    You should create a ResourceManager instance to open a resx file like this:

    ResourceManager resources = new ResourceManager("<MyProjectNamespace>.Properties.Resources", typeof(<any type in the assembly>).Assembly);
    string myString = resources.GetString("myString");
    Bitmap myBitmap = resources.GetObject("myBitmap") as Bitmap;
    

    If they are the resources of a form you can also get them as following:

    ResourceManager resources = new ResourceManager(typeof(Form1));
    
    0 讨论(0)
  • 2020-12-11 06:25

    Try using ResourceManager in the System.Resources Namespace. Obviously, it depends a bit on what you are trying to retrieve, but mine looks like this:

    ResourceManager.GetString("String1", resourceCulture);
    
    0 讨论(0)
提交回复
热议问题