Microsoft Communities

Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How does parenting work with ToolStrip controls?

The concept of container ownership and parenting is more complex in ToolStrips than in a typical Windows Forms container control. That is necessary to support dynamic scenarios such as overflow, sharing drop downs across multiple ToolStrip items and to support spawning ContextMenuStrips from controls.

The following lists parenting related properties and an explanation of their use

ToolStripItem ToolStripDropDown.OwnerItem

OwnerItem is used to access the item which sourced the dropdown. This is analogous to ContextMenuStrip.SourceControl, but instead of returning Control it returns ToolStripItem.

Control ContextMenuStrip.SourceControl

Indentical in function to ContextMenu's SourceControl. Used to determine which control sourced the ContextMenuStrip when multiple controls share the same ContextMenuStrip.

ToolStrip ToolStripItem.GetCurrentParent()

Rather than expose r/w Parent, we provide a read only accessor to the property via this method. Parent differs from Owner in that it will return the current ToolStrip in which the item is displayed within which may be the Overflow.

ToolStrip ToolStripItem.Owner()

This returns the ToolStrip whose Items collection contains this ToolStripItem. This is the best way to reference ImageList or other properties in the top level ToolStrip without writing special case code to handle overflow.



Page view counter