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

前端 未结 2 1805
粉色の甜心
粉色の甜心 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(".Properties.Resources", typeof().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));
    

提交回复
热议问题