Iterating through menuitems

M

MIGUEL?N.

Hi all,

I must globalize my application and therefore i must fill the text of
all controls of each form programatically.

When controls, I perform:

foreach (Control c in this.Controls)
{
// rm is my resource manager and culture is the current culture
c.Text = rm.GetString("ClientesForm" + "_" + c.Name, culture);
}

What's my surprise when I discover that MainMenu is not a Control;
it's a Menu object!

So I try to do the same with "Menu m in this.Menu". Then VS.NET tells
me that menuitems can't be iterated with foreach.

What's the way to iterate through menuitems in order to get the text
filled?

Thanks very much.
 
J

Jochen Kalmbach

MIGUEL?N. said:
Hi all,

I must globalize my application and therefore i must fill the text of
all controls of each form programatically.

When controls, I perform:

foreach (Control c in this.Controls)
{
// rm is my resource manager and culture is the current culture
c.Text = rm.GetString("ClientesForm" + "_" + c.Name, culture);
}

1. Be aware that "GetString" might return "null" !!!

We use the following wrapper function:

public static string BetterGetString(string text, ResourceManager rm,
CultureInfo culture)
{
if (text == null)
return string.Empty;
string res = rm.GetString(text, culture);
if (res == null)
return "<" + text + ">"; // indicate that this text was not translated
return res;
}
So I try to do the same with "Menu m in this.Menu". Then VS.NET tells
me that menuitems can't be iterated with foreach.


foreach (MenuItem m in this.Menu.MenuItems)
{
//...
}
 
M

MIGUEL?N.

First of all, thanks and sorry, probably my post was not very well
explained. I knew how to iterate with "foreach" in a Menu.MenuItems
collection. The problem is that I can't access the MenuItem.Name
property as I do it with the previous foreach looping, for general
controls. So I don't know how to load menuitems names programatically.
That's my problem.

Any ideas?
 

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