Sunday, June 22, 2008

Improved Resource file project template in vs2008

Visual Studio 2008 resource file project template is now more improved! and more usable.It has very user friendly and easy to edit environment, providing the user with the ease of managing resource better than ever. I have been using resource file since Visual Studio 2003. Previously I got to write code and use resource manager to pull the resources from the embedded resource file. And there are maintenance hassles to load a resource only once. We did lot of engineering previously to resolve the easy management and developer friendly architecture for resource accessibility. Now resource management with Visual Studio 2008 resource file template is a child's job.


What can be added in resource file


Now we can add different type of resource file just with few mouse click, isn't it great. Okay, here is the list of file type you can add as a resource file in resource file template.

  • String
  • Image
  • Icon
  • Audio
  • Files
  • Other(Virtually every thing!)



So there is lot to work with resource file. The magic is you can add these files with drag and drop from any location. Adding resources is that much easy. Still you have some traditional way of adding resource, you can add new resource and also add existing file from the disk. for this we have to click on "Add Recourse" button in Resource Management Window.



Access Modifier


Resource file and its type has few access modifier just like our class access modifier. If you set access modifier as "No code generation"  no designer generated code will be generated! ... this means now we don't have to write any manager class to manage and pull the resources from embedded resource file if we choose access modifier other than "No code generation". Here are the options we have in access modifier.

  • Internal
  • Public
  • No code generation


Visual Studio 2008 will automatically write a class and code for you so what you can access your files right way. This is one of the major improvement in resource file template of Visual Studio 2008. If you set access modifier as "Internal" your resource can only be accessed from the container project of the resource file, that implies what you can not access resources, that are marked as internal, from out side the project. So of course setting the access modifier to "Public" will made our resource accessible from any where.


I have used string file in in couple of my projects and did all custom codes to manage those. Now I use resource file right way because its so easy. Here is a view what designer generates for you.



Resource File "IntelliSense"


Since we have a designer generated code so we can use the class right way in our code and also enjoy the facility of intellisence. A very beautiful feature is that if we will get the object as typed object, means if we added string type it will give use string object, and if we have added image in our resource file it will return a Image Type object. so its pretty smart and we can bind it to a Image Control to display it.



Well another thing that I want to share, that, its has different type of view in resource manager window. we can switch to thumb nail mode if we are using image and easily locate which image we are looking for. Of Course we can also filter our resource using resource type selector.

NOTE: Each Resource is added against a key so. Key must be unique.

No comments:

Post a Comment