本文整理汇总了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");
}
示例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");
}
}
}
示例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();
}
}