' Create a ToolStripDropDownButton control and add it ' ContextMenuStrip control's Opening event.ĪddHandler fruitContextMenuStrip.Opening, AddressOf cms_Opening Private fruitContextMenuStrip As ContextMenuStripįruitContextMenuStrip = New ContextMenuStrip() ' SourceControl determination with reuse. ' It also demonstrates dynamic item addition and dynamic ' This code example demonstrates how to handle the Opening event. It is optimized to true based on empty entry. Populate the ContextMenuStrip control with its default items.į("Apples") į("Oranges") į("Pears") Add custom item (ToolStripDropDownButton or ToolStripMenuItem)į("Source: " + tsi.GetType().ToString()) Clear the ContextMenuStrip control's Items collection.į("Source: " + c.GetType().ToString()) ToolStripDropDownItem tsi = fruitContextMenuStrip.OwnerItem as ToolStripDropDownItem Acquire references to the owning control and item.Ĭontrol c = fruitContextMenuStrip.SourceControl as Control dynamic item addition and dynamic SourceControl This event handler is invoked when the ContextMenuStrip This is important for correct placement in the z-order. Add a button to the form and assign its ContextMenuStrip.ī.Location = new (60, 60) ī.ContextMenuStrip = fruitContextMenuStrip Add the ToolStrip control to the Controls collection. This.ContextMenuStrip = fruitContextMenuStrip Assign the ContextMenuStrip to the form's Dock the MenuStrip control to the top of the form.įruitToolStripMenuItem.DropDown = fruitContextMenuStrip ToolStripMenuItem fruitToolStripMenuItem = new ToolStripMenuItem("Fruit", null, null, "Fruit") Create a new MenuStrip control and add a ToolStripMenuItem. ToolStripDropDownButton control's DropDown menu.įruitToolStripDropDownButton.DropDown = fruitContextMenuStrip Assign the ContextMenuStrip control as the Dock the ToolStrip control to the top of the form. Ts.Items.Add(fruitToolStripDropDownButton) ToolStripDropDownButton fruitToolStripDropDownButton = new ToolStripDropDownButton("Fruit", null, null, "Fruit") to the ToolStrip control's Items collections. Create a ToolStripDropDownButton control and add it ContextMenuStrip control's Opening event.įruitContextMenuStrip.Opening += new (cms_Opening) Create a new ContextMenuStrip control.įruitContextMenuStrip = new ContextMenuStrip() Private ContextMenuStrip fruitContextMenuStrip SourceControl determination with reuse. It also demonstrates dynamic item addition and dynamic This code example demonstrates how to handle the Opening event. The following code example demonstrates a ContextMenuStrip with dynamic item addition, dynamic SourceControl determination with reuse, and handling of the Opening event. ![]() ClassInterfaceAttribute ComVisibleAttribute Examples
0 Comments
Leave a Reply. |