質問

It's easy to add strings to a ToolStripDropDownButton as a new DropDownItem. What I need is to add a custom object to the DropDownItems so that I can assign a key/value like object to the DropDownItem.

How may I achieve this?

役に立ちましたか?

解決

ToolStripItems can only display text and images and don't take objects. You can try sneaking an object in the Tag property of the button:

  ToolStripDropDownButton b = new ToolStripDropDownButton();
  b.DropDownItems.Add(new ToolStripButton("Hello") { Tag = new Something() });

and then when you handle the click event, inspect the Tag property for your object.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top