maybe a bit OT for this newsgroup, but I know that people here use C#, too.
So, does anyone know how the MFC string-table technique map to C#/WinForm?
I initially thought about using an integer->string map in C#, but is there
some built-in mechanism to manage that?
Thanks,
Giovanni
"Giovanni Dicanio" <giovanniD...@REMOVEMEgmail.com> ha scritto nel
messaggio news:ugqw1g7L...@TK2MSFTNGP03.phx.gbl...
> So, does anyone know how the MFC string-table technique map to C#/WinForm?
...after some web search, it seems that C# has a ResourceManager class for
that purpose.
Giovanni
You can also use assembly resources "embedded" in your C# app. Add a
resource (resx) file to your project, set it's namespace property if
desired.
Open it and add string resources (or other types).
Then in your code you can use a simpler way to access the strings than the
ResourceManager:
//example
string str = MyResourcesNamespace.Resource1.String1;
where MyResourcesNamespace is the namespace I specified, Resource1 is the
resx file I added, and String1 is the name of a string resource I added.
So simple even a C++ guy can do it :)
Mark
>
> Giovanni
>
>
> Then in your code you can use a simpler way to access the strings than the
> ResourceManager:
>
> //example
> string str = MyResourcesNamespace.Resource1.String1;
>
>
> where MyResourcesNamespace is the namespace I specified, Resource1 is the
> resx file I added, and String1 is the name of a string resource I added.
Thanks Mark!
It is simpler than the ResourceManager class!
> So simple even a C++ guy can do it :)
;-)
Giovanni
It's simpler because Visual Studio does the resource manager work for you!
I thought I'd add (in case you didn't see it) you can also use localized
resources this way.
Here's an example:
Walkthrough: Localizing Windows Forms
http://msdn.microsoft.com/en-us/library/y99d1cd3(VS.71).aspx
The link shows using a ResourceManager to access the strings, but if you add
a resource file like I described in my last post, the designer generates
that code wrapped in a class.
The resources in that first file become the neutral (not language specific)
resources.
To add culture-specific strings, you can add another resource file with the
same name except with a culture info name (e.g. Resource1.fr-FR.resx).
After adding the same named strings to that resource file, a thread's
CurrentUICulture setting will determine which resource is used:
// Set the current thread's CurrentUICulture
Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr-FR");
// the thread's CurrentUICulture determines where the string is loaded from!
string str = MyResourcesNamespace.Resource1.String1;
I really like how easy the C# dev environment makes this :)
Cheers,
Mark
...and if you add localized resources, don't forget to deploy the magically
generated satellite assemblies!
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
Cheers,
Giovanni
Thats how we use it and it works fine for us.
--
Ajay
Tom
"Ajay Kalra" <ajay...@yahoo.com> wrote in message
news:93878438-7A57-4D74...@microsoft.com...
Yes, Tom.
After I discovered this .NET mechanism, I find it better than the MFC one.
There is lots of work for MFC improvement to be done :)
G
Or move to the superior environment :-)
--
Ajay