0

Hi,

I am trying to add 2 menuItems to a toolstrip menu. I cant get it to work and wonder what I am doing wrong.

Also I like to add a click event to those items each that will open up the respective URL for each item "http://www.google.com" and "http://www.yahoo.com"

//Now add To menu
  			List<String^> All = gcnew List<String^>();
			All.Add("Google");
			All.Add("Yahoo");
			ToolStripMenuItem^ newItem = gcnew ToolStripMenuItem();
			
			for( int i = 0; i < All ->Count; i++ )
			{
				newItem = gcnew ToolStripMenuItem(); 
				newItem->Text = All[i]->ToString();
				newItem->Click += gcnew EventHandler(ClickEvent); 
				MyMenuToolStripMenuItem->DropDownItems->Add(newItem);
			}

Edited by Jennifer84: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by jonsca
0

ToolStripMenuItem has a "Tag" property (I think all of the controls do) which you could use to store the URL. Rather than generating an event handler for each new URL, make a generic one that navigates to the URL in the tag.

What is the nature of the error when you try to add it to MyMenuToolStripMenuItem (also, what is the type of that variable?)? You may have to add that to your ToolStrip as an additional step.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.