本文整理匯總了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;
}