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);
			}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.