I have a System.Windows.Form class (my main class). There is a RootMenu object. This is my own custom object. I'm trying to loop through the RootMenu object and on each pass add a ToolStripMenuItem to a ContextMenuStrip (which I named ContextMenu). The RootMenu object contains a List. Links have Names and Urls (both strings).
When the form loads my "Factory" class loads me up a RootMenu object, which I then pass into the ProcessMenu method.
Code Excerpt Here:
private void ProcessMenu(RootMenu rm)
{
foreach (var lnk in rm.Links)
{
var tsmi = new ToolStripMenuItem(lnk.Name, null, new EventHandler(Navigate));
tsmi.ToolTipText = lnk.Url;
ContextMenu.Items.Add(tsmi);
}
}
private void Navigate(object sender, EventArgs e)
{
var tsmi = (ToolStripMenuItem) sender;
System.Diagnostics.Process.Start(tsmi.ToolTipText);
}
Do you see how I have to store the lnk.Url in the ToolTipText? In the VB6 days all the controls had the "tag" property. You used to be able to stuff extra stuff into the control that you would need later on. I don't want to use the tooltip for this, but what are my alternatives? Storing all the Urls in a Hash/Dictionary using the name as a key? I may not always have unique names, so I would like to avoid this route. What is the proper way to handle this in .NET? Maybe I missing some basic concept I have never been exposed to.