An example of c using a resource file

  • 2020-06-07 05:12:33
  • OfStack

Mainly through GetString and GetObject methods in System.Resources.ResourceManager class. The return value of both methods is of type Object, and the required parameter is the only id for the resource (the only id used to add the resource when creating the resource).


First, instantiate an object of the ResourceManager class.


// Create a class 1 Two instantiated objects 
ResourceManager rm = new ResourceManager ( "Images" , Assembly.GetExecutingAssembly ( ) ) ;

The method can then be called to use the resource.


// Cast type 
Icon ico =  (( Icon ) ( rm.GetObject("demo.ico") )) ;// For icon 
Image canceloff = ( ( Image ) ( rm.GetObject ( "ok-on.png" ) ) ) ;// Get photo 
string str=((string)(rm.GetString("MyStr")));// Get string 


This allows the resource to be used. Of course, remember to import resources before using them!


Related articles: