Resource file again

A

Alan T

I added a resource file into my project, to store the caption of buttons and
labels..
How do I make use of this resource file to dynamically assign to the buttons
and labels ?
 
A

Alan T

It is a Windows application.
What I want is to dynamically store the string to the form's label and
buttons'caption.

This is useful if we want to internationalize the application with other
language.
 
S

Stoitcho Goutsev \(100\)

Alan,

The easiest would be to turn on the localization for the form. Just set the
form's Localizable property to *true*. Once you do this all the form and
form's controls properties such as Text, Size, Location, etc will go to a
resource file and the designer will generate the code to load them from
there. If you want to use your own resource file I'm afraid you need to read
the values and set the controls by yourself.

Anoither solution would be to use the application settings for storing the
values. In the designer select a control and then from the property window
expand the "Application Settings" node, which is the first on the top. You
can choose any control property form the PropertyBinding collcection and you
can also choose whether the property should go in the user or global
(application) settings.
 
A

Alan T

Hi,

Is what I did is correct ?

Right click the project
Add New Item
Choose 'Settings File'
Define the entries in the file

Then -
"In the designer select a control and then from the property window
expand the "Application Settings" node, which is the first on the top. You
can choose any control property form the PropertyBinding collcection and
you
can also choose whether the property should go in the user or global "

What will be the differences between 'user' and 'application' ?
 
S

Stoitcho Goutsev \(100\)

Alan,
All settings in the application scope apply for all users. The settings in
the user scope are per user, thus the proeprty values can be different
depending on who runs the applciation.
 
A

Alan T

So I think I should use the 'Application'.

Stoitcho Goutsev (100) said:
Alan,
All settings in the application scope apply for all users. The settings in
the user scope are per user, thus the proeprty values can be different
depending on who runs the applciation.
 
A

Alan T

Hi,

In addition, is there really a way, I mean using the resource file to
configure the display caption of labels, buttons or treeview nodes text,
listview column text.
Is resource file's purpose for that ?
 
S

Stoitcho Goutsev \(100\)

Yes, this is the place for that and as I said for WinForms it works
atomatically when localization is turned on. VS will save to resource and
generate a code for reading the values from there for any property
attributed with LocalizableAttribute.
 
S

Stoitcho Goutsev \(100\)

Alan,

There might be as many resources as you want with one application. the
resources can be stored in on the disk as resx files, embeded in the an
assembly, in satellite assembly, etc. I addtion any files that you want can
be added as a embedded resource to your assembly.
The resource file the windows forms form or user control uses to store
localized proeprty values is hidden by default. In order to see it click on
the "Show All Files" button from the solution explorer toolbar. Then you can
see [+] sign next to the form or user control node on the tree. Expand the
node and you'll see the resx file.

In order to read resource at runtime you can use the ResourceManager class
or alternatively you can use Assembly.GetManifestResourceStream method.

My suggestion is to turn on the localization on some test form and look at
the InitializeComponent method the code that VS generates.
 
A

Alan T

Back to the settings file:
What will be the effect between using the "user" and "application" scope?

eg.
I define that as "user" scope and my user runs my application.

Stoitcho Goutsev (100) said:
Alan,

There might be as many resources as you want with one application. the
resources can be stored in on the disk as resx files, embeded in the an
assembly, in satellite assembly, etc. I addtion any files that you want
can be added as a embedded resource to your assembly.
The resource file the windows forms form or user control uses to store
localized proeprty values is hidden by default. In order to see it click
on the "Show All Files" button from the solution explorer toolbar. Then
you can see [+] sign next to the form or user control node on the tree.
Expand the node and you'll see the resx file.

In order to read resource at runtime you can use the ResourceManager class
or alternatively you can use Assembly.GetManifestResourceStream method.

My suggestion is to turn on the localization on some test form and look at
the InitializeComponent method the code that VS generates.


--
HTH
Stoitcho Goutsev (100)
Alan T said:
How do I read the resource file of a Windows Form? Is that with
extension.resx ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top