Inheritance: System.Windows.Forms.ToolStripDropDown
コード例 #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates one of three different types of drop-down toolbar items.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private ToolStripItem CreateDropDownToolBarItem(XmlNode node, int type)
		{
			ToolStripItem item;

			// True if the drop-down button is split into two segments, one for the arrow and
			// one for the icon. False if there is no behavioral distinction between the arrow
			// and icon portions of the button.
			bool split = GetBoolFromAttribute(node, "split", true);

			if (split)
			{
				item = ToolStripItemExtender.CreateSplitButton();
				((ToolStripSplitButton)item).ButtonClick += HandleItemClicks;
				((ToolStripSplitButton)item).DropDown.Closed += HandleToolBarItemDropDownClosed;

				if (type == 3)
					((ToolStripSplitButton)item).DropDownOpening += HandleToolBarItemDropDownOpened;
				else
					((ToolStripSplitButton)item).DropDownOpened += HandleToolBarItemDropDownOpened;
			}
			else
			{
				item = ToolStripItemExtender.CreateDropDownButton();
				((ToolStripDropDownButton)item).DropDown.Opened += HandleToolBarItemDropDownOpened;
				((ToolStripDropDownButton)item).DropDown.Closed += HandleToolBarItemDropDownClosed;
			}

			switch (type)
			{
				case 1:
					// Create a drop-down that will act like a drop-down toolbar.
					ToolStripDropDown dropDown = new ToolStripDropDown();
					dropDown.LayoutStyle = ToolStripLayoutStyle.StackWithOverflow;
					((ToolStripDropDownItem)item).DropDown = dropDown;
					break;

				case 2:
					// Create a drop-down that will act like a drop-down menu.
					ToolStripDropDownMenu dropDownMenu = new ToolStripDropDownMenu();
					dropDownMenu.ShowImageMargin = GetBoolFromAttribute(node, "showimagemargin", true);
					dropDownMenu.ShowCheckMargin = GetBoolFromAttribute(node, "showcheckmargin", false);
					((ToolStripDropDownItem)item).DropDown = dropDownMenu;
					break;

				case 3:
					// Create a drop-down for a custom control.
					CustomDropDown cdd = new CustomDropDown();
					cdd.AutoCloseWhenMouseLeaves = false;
					((ToolStripDropDownItem)item).DropDown = cdd;
					break;
			}

			item.DisplayStyle = ToolStripItemDisplayStyle.Image;
			return item;
		}
コード例 #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void ReadToolbarItems(XmlNode node, object parentItem)
		{
			while (node != null)
			{
				ToolStripItem item = ReadSingleItem(node, false);

				if (parentItem is ToolStrip)
					((ToolStrip)parentItem).Items.Add(item);
				else if (parentItem is ToolStripDropDownItem)
				{
					ToolStripDropDownItem pItem = (ToolStripDropDownItem)parentItem;

					// If the parent item's drop-down type is a menu,
					// then make sure the text shows.
					if (pItem.DropDown is ToolStripDropDownMenu)
						item.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText;

					if (!(item is ToolStripControlHost))
						pItem.DropDownItems.Add(item);
					else
					{
						// When we're a control host then put ourselves inside a CustomDropDown.
						CustomDropDown dropDown = new CustomDropDown();
						dropDown.AddHost(item as ToolStripControlHost);
						dropDown.AutoCloseWhenMouseLeaves = false;
						pItem.DropDown = dropDown;
					}
				}

				// This must be done after the item has been added to a item collection.
				item.Visible = GetBoolFromAttribute(node, "visible", true);

				if (node.ChildNodes.Count > 0)
					ReadToolbarItems(node.FirstChild, item);

				node = ReadOverJunk(node.NextSibling);
			}
		}