Globalization of Menus

  • Thread starter Thread starter Thore Berntsen
  • Start date Start date
T

Thore Berntsen

I'm working on globalization of my retail Pocket PC application.

I found much help in this article the article "Build World-Ready Device
Applications" on MSDN.
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/worldready.asp)

The only thing I need help with, wich this article dosen't cover, is menus.
I could fix that myself, but I need to find the Name (not Text!) of every
MenuItem component on my Form. Does anyone have any ideas on how this can be
done?

Thore Berntsen
VBD, Norway.
 
I want to find all MenuItem's on my Form and lookup the gloablized text in
my resource dll's using ResourceManager.GetString. My resources is organized
the same way that in the MSDN article. That means that I have to get the
name of the MenuItem in order to pass it to the GetString method. I could of
course hardcode this, but I'm trying to automate this process a bit (againt
see the MSDN article)

Thore
 
MenuItem inherits from Menu : Component : MarshalByRefObject : Object
So as you can see there is no Control in that hierarchy which is why the
approach discussed in the article does not work. I am aware of no other way
of getting the name of a menu item.

What you could do is create your own MenuItemEx that adds that property
e.g.:
namespace System.Windows.Forms{
public class MenuItemEx : MenuItem{
public string Name;
}
}

Then wherever you have a MenuItem declared change the declaration to
MenuItemEx and do the same for where it gets created (= new MenuItemEx).
Then explicitly set the Name property to some string and use that in your
resources. Frankly, I wouldn't get into all that trouble as you will lose
designer support either for the menus because you will add them in your
constructor/OnLoad or for the entire form if you choose to directly edit the
InitializeComponent.

Regardless of the above, I wouldn't use the approach described in the
article at all. It is much slower than hardcoding the control IDs. NETCF
form startup (which is where assigning Text usually take place) is slow
enough as it is without adding reflection to it. Plus I wouldn't want to tie
myself to a scheme where I cannot change control names later due to
refactoring or whatever.

Cheers
Daniel
 
Back
Top