当前位置: 首页>>代码示例>>C#>>正文


C# ToolStripItemCollection.Remove方法代码示例

本文整理汇总了C#中System.Windows.Forms.ToolStripItemCollection.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# ToolStripItemCollection.Remove方法的具体用法?C# ToolStripItemCollection.Remove怎么用?C# ToolStripItemCollection.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.ToolStripItemCollection的用法示例。


在下文中一共展示了ToolStripItemCollection.Remove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Remove_StandAlone

		public void Remove_StandAlone ()
		{
			ToolStrip toolStrip = CreateToolStrip ();
			ToolStripItemCollection items = new ToolStripItemCollection (
				toolStrip, new ToolStripItem [0]);

			MockToolStripButton buttonA = new MockToolStripButton ("A");
			MockToolStripButton buttonB = new MockToolStripButton ("B");
			MockToolStripButton buttonC = new MockToolStripButton ("B");
			items.Insert (0, buttonA);
			items.Insert (0, buttonB);

			items.Remove (buttonB);
			Assert.AreEqual (1, items.Count, "#A1");
			Assert.AreEqual (0, itemsRemoved.Count, "#A2");
			Assert.AreSame (buttonA, items [0], "#A3");

			items.Remove ((ToolStripItem) null);
			Assert.AreEqual (1, items.Count, "#B1");
			Assert.AreEqual (0, itemsRemoved.Count, "#B2");
			Assert.AreSame (buttonA, items [0], "#B3");

			items.Remove (buttonC);
			Assert.AreEqual (1, items.Count, "#C1");
			Assert.AreEqual (0, itemsRemoved.Count, "#C2");
			Assert.AreSame (buttonA, items [0], "#C3");

			items.Remove (buttonA);
			Assert.AreEqual (0, items.Count, "#D1");
			Assert.AreEqual (0, itemsRemoved.Count, "#D2");

			items.Remove (buttonA);
			Assert.AreEqual (0, items.Count, "#E1");
			Assert.AreEqual (0, itemsRemoved.Count, "#E2");

			// remove item owned by other toolstrip
			ToolStrip otherToolStrip = new ToolStrip ();
			MockToolStripButton buttonD = new MockToolStripButton ("B");
			otherToolStrip.Items.Add (buttonD);
			Assert.AreSame (otherToolStrip, buttonD.Owner, "#F1");
			Assert.IsNull (buttonD.ParentToolStrip, "#F2");
			items.Remove (buttonD);
			Assert.AreEqual (0, items.Count, "#F3");
			Assert.AreEqual (0, itemsRemoved.Count, "#F4");
			Assert.AreSame (otherToolStrip, buttonD.Owner, "#F5");
			Assert.IsNull (buttonD.ParentToolStrip, "#F6");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:47,代码来源:ToolStripItemCollectionTest.cs

示例2: MergeMenu

		private void MergeMenu(ToolStripItemCollection source, ToolStripItemCollection dest)
		{
			while(source.Count > 0)
			{
				ToolStripMenuItem item = (ToolStripMenuItem) source[0];
				if(item.MergeAction == MergeAction.Insert)
				{
					for(int index = 0; index < dest.Count; ++index)
					{
						if(dest[index].MergeIndex > item.MergeIndex)
						{
							dest.Insert(index, item);
							break;
						}
					}
				}
				else if (item.MergeAction == MergeAction.Append)
				{
					dest.Add(item);
				}
				else if (item.MergeAction == MergeAction.MatchOnly)
				{
					ToolStripMenuItem match = null;
					foreach(ToolStripMenuItem destitem in dest)
					{
						if(destitem.Text == item.Text)
						{
							match = destitem;
							break;
						}
					}
					if(match == null)
						throw new ApplicationException("Can't merge with nonexistent menu '" + item.Text + "'");

					MergeMenu(item.DropDownItems, match.DropDownItems);
					source.Remove(item);
				}
				else
				{
					throw new ApplicationException("Unsupported menu merge action");
				}
			}
		}
开发者ID:zcnet4,项目名称:lua-tilde,代码行数:43,代码来源:Manager.cs

示例3: FilterUnavailableItems

		private static void FilterUnavailableItems(ToolStripItemCollection items)
		{
			List<ToolStripItem> unavailableItems = new List<ToolStripItem>();
			foreach (ToolStripItem toolStripItem in items)
			{
				if (!toolStripItem.Available)
				{
					unavailableItems.Add(toolStripItem);
				}
				else if (toolStripItem is ToolStripMenuItem)
				{
					ToolStripMenuItem toolStripMenuItem = (ToolStripMenuItem) toolStripItem;
					if (toolStripMenuItem.DropDownItems.Count > 0)
					{
						FilterUnavailableItems(toolStripMenuItem.DropDownItems);
						if (toolStripMenuItem.DropDownItems.Count == 0)
							unavailableItems.Add(toolStripItem);
					}
				}
			}

			foreach (ToolStripItem unavailableItem in unavailableItems)
			{
				items.Remove(unavailableItem);
				unavailableItem.Dispose();
			}
		}
开发者ID:nhannd,项目名称:Xian,代码行数:27,代码来源:TileControl.cs


注:本文中的System.Windows.Forms.ToolStripItemCollection.Remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。