poppy wrote:
I am having trouble creating a menu item.
The Code I have:
private void NewLoad(object sender, System.EventArgs e) {
//error here
ToolStripItem mn = (ToolStripItem)sender;
}
The error I get is :
"Unable to cast object of type 'System.Windows.Forms.ContextMenuStrip' to
type 'System.Windows.Forms.ToolStripItem'."}
When I hover my mouse over "object sender" I get "{
[System.Windows.Forms.ContextMenuStrip], Name: contextMenuStrip1, Items: 6} "
What am I doing wrong. I'm going to cry now.
Don't cry :( Basically you are mixing up _containers_ and _things that
go in containers_. A ToolStripItem is "an element such as a button,
combo box, text box, or label that can be contained in a ToolStrip
control or a ToolStripDropDown control" - so it's a _thing that goes in
a container_. But a ContextMenuStrip is a ToolStripDropDownMenu, which
is a ToolStripDropDown, which is a ToolStrip, which "Provides a
container for Windows toolbar objects". So a ContextMenuStrip is a
_container_
So what we need to see now is the code where you hook up this event
handler, and we can tell you what's wrong with it. It looks like you've
hooked up to a container event when you meant to hook up to an item
event, but we need to see it to be sure.
--
Larry Lard
Replies to group please