本文整理汇总了C#中System.Windows.Forms.ToolStripItemCollection.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# ToolStripItemCollection.Cast方法的具体用法?C# ToolStripItemCollection.Cast怎么用?C# ToolStripItemCollection.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ToolStripItemCollection
的用法示例。
在下文中一共展示了ToolStripItemCollection.Cast方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertHasNoMenuWithText
/// <summary>
/// Assert that the strip has no menu item with the specified text.
/// </summary>
/// <param name="items"></param>
/// <param name="text"></param>
/// <returns></returns>
private static void AssertHasNoMenuWithText(ToolStripItemCollection items, string text)
{
if (items.Cast<ToolStripItem>().Any(item => item is ToolStripMenuItem && (item as ToolStripMenuItem).Text == text))
{
Assert.Fail("item " + text + " was unexpectedly found in a context menu");
}
}
示例2: ActualItems
private IEnumerable<ToolStripItem> ActualItems(ToolStripItemCollection items)
{
return items.Cast<ToolStripItem>().Where(item => !(item is ToolStripSeparator));
}
示例3: CloneItems
private List<ToolStripItem> CloneItems(ToolStripItemCollection collection)
{
var list = new List<ToolStripItem>();
if (collection != null)
{
list.Add(new ToolStripSeparator());
var enumerable = collection.Cast<ToolStripItem>();
foreach (var toolStripItem in enumerable)
{
if (toolStripItem is ToolStripSeparator)
{
list.Add(new ToolStripSeparator());
}
else
{
var toolStripMenuItem = toolStripItem as ToolStripMenuItem;
if (toolStripMenuItem != null)
{
var item = new ToolStripMenuItem
{
Name = toolStripMenuItem.Name,
Size = toolStripMenuItem.Size,
Text = toolStripMenuItem.Text,
ToolTipText = toolStripMenuItem.ToolTipText,
ShortcutKeys = toolStripMenuItem.ShortcutKeys,
ShortcutKeyDisplayString = toolStripMenuItem.ShortcutKeyDisplayString,
ShowShortcutKeys = toolStripMenuItem.ShowShortcutKeys
};
var events = (EventHandlerList)eventsPropertyInfo.GetValue(toolStripMenuItem, null);
var secret = eventClickFieldInfo.GetValue(null);
var handlers = events[secret];
events = (EventHandlerList)eventsPropertyInfo.GetValue(item, null);
events.AddHandler(secret, handlers);
list.Add(item);
}
}
}
}
return list;
}
示例4: FindOrCreateAlgoMenuItem
private static ToolStripMenuItem FindOrCreateAlgoMenuItem(ToolStripItemCollection parent, string algorithm)
{
ToolStripMenuItem algoItem = parent.Cast<ToolStripMenuItem>().FirstOrDefault(item => item.Text.Equals(algorithm));
if (algoItem == null)
{
algoItem = new ToolStripMenuItem()
{
Text = algorithm
};
parent.Add(algoItem);
}
return algoItem;
}