![]() |
Desktop Development »
Miscellaneous »
Miscellaneous Controls
Intermediate
Resource Editor .NETBy Bill SaylesA utility to easily refresh embedded graphic resources in a .NET assembly. |
C#.NET 1.0, Win2K, WinXP, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

I am sure Microsoft thought they were being progressive when they replaced the good ol' .rc file with the XML-based .resX file at the release of Visual Studio.NET. Unlike its predecessor, when you add a resource such as a bitmap to a .NET project through the properties of a Windows form, the actual bitmap binary data is embedded in the associated .resX file. This does not allow update or modification of the bitmap without removing and then adding the bitmap again to the form. Also, you can no longer easily add resources to the assembly not associated with an object managed by the designers. Microsoft includes a sample application which provides a rudimentary resource editor function with Visual Studio.NET, but it also only supports embedding the binary data and does not facilitate easy update of the resources.
The Resource Editor.NET utility is built off this sample application. It generates a .resources or .resX file which can be embedded in any .NET assembly project, and it also saves a .resourcesConfig file which saves the file locations for the resources you added. It currently supports bitmap, icon and string resources. It has saved countless hours during usability testing and language adaptation efforts.
The Resource Editor .NET allows you to add bitmaps, icons and resource strings to use in your assemblies by making use of the classes in the System.Resources namespace. When you add a named resource, the full path information for the object is retained and saved to a .resourcesConfig XML file with the same name as the .resources or .resX file you specify when saving your work in the editor. You can then add both files to your project in the Project Explorer.
<?xml version="1.0"?>
<Resources Extension=".resources">
<Resource Name="ButtonEnglishNormal"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-english.bmp" Value="" />
<Resource Name="ButtonEnglishDisabled"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-english-na.bmp" Value="" />
<Resource Name="ButtonEnglishPressed"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-english-on.bmp" Value="" />
<Resource Name="ButtonEnglishOver"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-english-over.bmp" Value="" />
<Resource Name="ButtonEspanolNormal"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-espanol.bmp" Value="" />
<Resource Name="ButtonEspanolDisabled"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-espanol-na.bmp" Value="" />
<Resource Name="ButtonEspanolPressed"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-espanol-on.bmp" Value="" />
<Resource Name="ButtonEspanolOver"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-espanol-over.bmp" Value="" />
<Resource Name="ButtonRoundGlassNormal"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-roundglass.bmp" Value="" />
<Resource Name="ButtonRoundGlassDisabled"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-roundglass-na.bmp" Value="" />
<Resource Name="ButtonRoundGlassPressed"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-roundglass-on.bmp" Value="" />
<Resource Name="ButtonRoundGlassOver"
Type="System.Drawing.Bitmap"
FileName="C:\CodeSubmissions\ResourceEditor.NET\images\bt-roundglass-over.bmp" Value="" />
</Resources>
You can freely rename the resources or change the file specified. When you press Save, the XML file and the chosen .NET resource binary format file is generated. You can also just reopen the file to cause any changes to the referenced bitmap or icon files in the existing locations as specified in the .resourcesConfig have been modified and you want the changes included in the assembly during the next build. All you have to do is add the resulting .resources or .resX file to the project for the assembly you want to embed the resources in.
Although I don't use this tool for this purpose, you could use it for enabling refresh for bitmaps or icons associated to objects using the forms designer built into Visual Studio .NET. This requires one extra step.
Unfortunately, if you add or remove bitmaps or icons afterwards using the forms designer, you would need to repeat the process to incorporate those changes. However, you can manipulate the .resourcesConfig XML file with a text editor to get around this.
The Resource Editor .NET has two modes. The first is the standard UI mode, where you open the application to an empty resource set or with an existing .resourcesConfig file as its first parameter. The second adds the command-line switch /Refresh, which supresses the GUI but will regenerate the .resources or .resX file associated with the .resourcesConfig file. The easiest way to use the tool is to add it as an external tool to Visual Studio .NET. Then when you select the .resourcesConfig file in the Project Explorer, you can either refresh or edit the resources from within the Visual Studio environment. The following two snapshots show how to set the tool up in the IDE.


Initial Release.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 17 Nov 2002 Editor: Nick Parker |
Copyright 2002 by Bill Sayles Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |