Just a small amount of text? That isn't very resourceful of you, young man!

by Michael S. Kaplan, published on 2007/03/17 18:59 -04:00, original URI: http://blogs.msdn.com/b/michkap/archive/2007/03/17/1902578.aspx


John's question was simple enough:

Anybody know a trick to have the Text properties of WinForm controls have their values stored in resource files rather than <formname>.Designer.cs?

When the text string is long, VS automatically puts the value in a resource string.  However, when the value is fairly short, VS stores the value in the Designer.cs file.

I want all my strings in a resource file.   Obviously, I can just code assignment statements during Load of the forms, but it seems like there should be some automatic way to tell VS to put all the strings in the resource file right from the UI editor.

And he is right -- the exact cutoff point in a newly created project is exactly 200 characters1; any time the text is longer than 200, it will be loaded from the form's associated resource file.

(If you are using .NET 1.0 then it won't be in a designer.cs file since they didn't exist yet. But the principle is still the same!)

People jumped in quickly with the answer -- just mark the form's Localizable property to to be true and then the text will always be in the form's resources (along with all of the other properties considered "localizable"....

And while the answer is technically correct to answer the generic question, it is not always the best way to proceed....

It is actually something one may want to carefully consider, since it fundamentally changes how the form is loaded and what tasks are done to accomplish the loading. But it is really the only way to force the property's contents to be loaded from resources in all cases, other than just manually doing that load yourself.

In the end, the string assigned directly directly from code rather than loaded from resources is presumably faster, a principle which may apply to the rest of the affected properties as well.

If the form is not intended to be localized, the manual resource load of the string may be the easier/faster way to get things done in the end....

 

1 - This is not characters in the user sense but in the developer sense -- the number of individual Unicode code points in UTF-16.

 

This post brought to you by ឦ (U+17a6, a.k.a. KHMER INDEPENDENT VOWEL QII)


no comments

Please consider a donation to keep this archive running, maintained and free of advertising.
Donate €20 or more to receive an offline copy of the whole archive including all images.

go to newer or older post, or back to index or month or day