What is a "resx" file?

Posted by ChUIMonster on 27-Feb-2009 10:18

The subject says it all

Well, ok, I'd also like to know when I need to pay attention to them. I notice, for instance, that they are sometimes included when people post code samples. Why? Are these something that I will need to provide when I deploy code?

I did crack a couple open and look at them but gray mush started running out my ears so I stopped doing that...

All Replies

Posted by Peter Judge on 27-Feb-2009 10:31

Well, ok, I'd also like to know when I need to pay

attention to them. I notice, for instance, that they

are sometimes included when people post code samples.

Why? Are these something that I will need to

provide when I deploy code?

I did crack a couple open and look at them but gray

mush started running out my ears so I stopped doing

that...

They're resource files - they (can) contain all sorts of info pertinent to the Form, like the images used, or translated strings or the even just the position of the non-visual stuff at the bottom of the design surface. The VD creates one per Form or visual class.

You can create your own - for translation, for instance - and share them. (I know this probably doesn't really help you much, but) Visual Studio has a decent interface for working with them, so you don't go and leak grey mush all over your keyboard*.

There's an overview here: http://msdn.microsoft.com/en-us/library/f45fce5x.aspx . Warning: earplugs may be required.

You will need to deploy them, if they exist.

-- peter

  • it's a pain to get out from between the keys, I find

Posted by ChUIMonster on 27-Feb-2009 10:39

Thanks. That helps.

The signal to noise ratio in those things seems quite low

Posted by Peter Judge on 27-Feb-2009 10:46

A quick racking of my brain (aka Google search) turns up a cople of ResX editors, most of which are targeted at string translations.

-- peter

Posted by Admin on 27-Feb-2009 12:37

In addition to what Peter has already mentioned. resx files are XML files. They start with a very, very long comment about what's in there, the XML Schema (XSD) and then eventually some resources.

Resources are contained in an XML serialized format together with their (data-type), System.String or System.Drawing.Image etc.. Binary resources rathe base64-encoded.

All images used in the Visual Designer go into the resx file. That means that every image appears in an resx file for every form that uses it (in a toolbar, on a button, as the icon,...).

Check the resourcehelper class from Progress (Progress.Util.ResourceHelper) it you wanna to to use the resx file for translations etc.

Posted by Admin on 10-Dec-2009 04:15

Does any of you guys tried to use one resx file for the whole project? I've got many forms and lots of icons (images) in it.  Icons like add, edit, delete are the same for every form, so in the output i've got lots of redundant data in those resx files. Is it even possible to make one resx containing images and other one to hold strings for the whole project?

Posted by Matt Baker on 10-Dec-2009 07:54

You can certainly create and use your own .resx files.  BUT the way the serializer works, each form is responsible for its own .resx files.  If you end up having the same image inserted into each .resx file you should do your images differently.  Instead of adding them to the form, load them after the call to initializecomponent in your own code.  The drawback is you won't see them in the designer, but you'll reduce the size of the .resx files and reduce the amount of duplicate code.

There might be a better way, I just not aware of one.

Posted by Admin on 10-Dec-2009 10:27

It would be nice to have such functionality to create one resx per media type and define in each form which file to use. Of course I could do as you wrote, but the drawback ... I think the best solution would be something like this: use designer as always but select a flag which says "do not put img's in resx", and after initialiseComponent do as Matthew wrote ;-)

Posted by Thomas Mercer-Hursh on 10-Dec-2009 11:28

I would think the other way to avoid duplication would be to put common functionality in a common class and use it everywhere that functionality was needed.

Or, is the .resx tied to the form, not the class?

Posted by Admin on 11-Dec-2009 02:50

tamhas wrote:

I would think the other way to avoid duplication would be to put common functionality in a common class and use it everywhere that functionality was needed.

Or, is the .resx tied to the form, not the class?

As far as I know class describes a form (if it inherits from one, so in this case class=form), but maybe you ment instance of a class, still what do you mean by tied?

Posted by Matt Baker on 11-Dec-2009 08:41

Visual Designer uses the file name of the current class that you are opening to find the .resx(s) [what is plural of resx anyway?... is resx even a noun?].  It strips the file extension and adds .resx.  With 10.2B its a little more complicated to handle multiple files, but the affect is the same.  The .resx(s) is/are passed to the designer along with the necessary code structure of the component when the form is loaded.

I just created a form with an imagelist and added several images to the image list.  I marked the image list as protected.  I then extended the base class, added a button to it, and set the image list and image index properties for the button to reference one of the images in the base class' imagelist object.   The .resx for both the base class and the child class contain the serialized form of the imagelist.  So in effect you end up loading the imagestream for the imagelist twice, once for the base class and once for each child class.  I've attached the code.

If you have multiple forms open, then each form is going to get its own copy of ALL the images referenced in the base class.  So if you have a base class that references all the images in your application you might end up with a couple hundred images loaded into memory, and then you get a second copy if you have multiple forms open.  This isn't very efficient.

But, then again, I might just be letting my imagination run wild and this really isn't a big problem.   It really depends on how many images you need and how big they are.

Anecdote:  early in visual designer development we had a 20MB memory leak every time you opened and closed the visual designer.  It turns out we had a 1 MB bitmap image that was used as the background for the toolbox.  The user would expand the Microsoft section of the controls and a new instance of the gradient image was loaded for each control.  Then you would close the form and reopen it, allocating another 20MB.   The fix was to reuse the background image instance and of course turn the image into a jpeg which was only about 2k in size.  The point of telling this is that if you have largish images or many small ones, you need to reuse them efficiently since they consume a lot more memory than a simple object instance.

Replaced zip file with 102a compatible project

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/testimageserialization.zip:550:0]

This thread is closed