문제

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