本文整理汇总了C#中System.Windows.Forms.ToolStripItemCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ToolStripItemCollection.Add方法的具体用法?C# ToolStripItemCollection.Add怎么用?C# ToolStripItemCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ToolStripItemCollection
的用法示例。
在下文中一共展示了ToolStripItemCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildMenu
public static void BuildMenu(ToolStripItemCollection items, IEnumerable<IEditorScript> scripts, Action<IEditorScript> callback)
{
foreach (var script in scripts)
{
if (script.Name.StartsWith("----"))
{
items.Add(new ToolStripSeparator());
}
else if (script.Children.Any())
{
var item = new ToolStripMenuItem(script.Name);
BuildMenu(item.DropDownItems, script.Children, callback);
items.Add(item);
}
else
{
items.Add(new ToolStripMenuItem(script.Name, null, (s, ev) =>
{
var query = script.Script; // Trigger execution
if (!string.IsNullOrEmpty(query))
{
callback(script);
}
}));
}
}
}
示例2: BuildMenu
public static void BuildMenu(ToolStripItemCollection items, IEnumerable<IEditorScript> scripts, Func<IEditorScript, Task> callback)
{
foreach (var script in scripts)
{
if (script.Name.StartsWith("----"))
{
items.Add(new ToolStripSeparator());
}
else if (script.Children.Any())
{
var item = new ToolStripMenuItem(script.Name);
BuildMenu(item.DropDownItems, script.Children, callback);
items.Add(item);
}
else
{
items.Add(new ToolStripMenuItem(script.Name, null, async (s, ev) =>
{
var text = await script.GetScript(); // Trigger execution
if (!string.IsNullOrEmpty(text))
{
await callback(script);
}
}));
}
}
}
示例3: FillMenuItems
private static void FillMenuItems(List<MySQL.Base.MenuItem> itemsBE, ToolStripItemCollection itemsFE)
{
foreach (MySQL.Base.MenuItem itemBE in itemsBE)
{
switch (itemBE.get_type())
{
case MySQL.Base.MenuItemType.MenuSeparator:
{
itemsFE.Add(new ToolStripSeparator());
}
break;
default:
{
ToolStripMenuItem itemFE = new ToolStripMenuItem();
itemFE.Tag = itemBE.get_name();
itemFE.Text = itemBE.get_caption();
itemFE.Enabled = itemBE.get_enabled();
if (MySQL.Base.MenuItemType.MenuCascade == itemBE.get_type())
{
FillMenuItems(itemBE.get_subitems(), itemFE.DropDownItems);
}
else
{
itemFE.Click += new EventHandler(OnMenuItemClick);
}
itemsFE.Add(itemFE);
}
break;
}
}
}
示例4: PopulateItems
private static void PopulateItems(ToolStripItemCollection items, IEnumerable<CommandMenuGroup> groups, CommandRegistry registry)
{
List<CommandMenuGroup> groupList = groups as List<CommandMenuGroup>;
if (groupList == null)
groupList = new List<CommandMenuGroup>(groups);
foreach (CommandMenuGroup group in groupList) {
if (group != groupList[0])
items.Add(new ToolStripSeparator());
foreach (CommandMenuEntry entry in group) {
if (entry.SubMenu != null)
items.Add(BuildToolStripMenu(entry.SubMenu, registry));
else {
CommandRecord record = registry.Lookup(entry.Key);
if (record != null) {
ToolStripMenuItem menuItem = new ToolStripMenuItem() {
Tag = entry.Key,
Text = record.DisplayName,
Image = record.Image,
ShortcutKeys = record.Shortcut,
ShortcutKeyDisplayString = record.ShortcutDisplay,
ToolTipText = record.Description,
};
items.Add(menuItem);
}
}
}
}
}
示例5: FillToolItems
/// <summary>
/// Fills items to the specified tool strip item collection
/// </summary>
public static void FillToolItems(ToolStripItemCollection items, XmlNode node)
{
switch (node.Name)
{
case "separator":
items.Add(GetSeparator(node));
break;
case "button":
items.Add(GetButtonItem(node));
break;
}
}
示例6: Apply
/// <summary>
/// Add the contents of this MergableMenu to a CommandBarMenu
/// </summary>
/// <param name="menu"></param>
public void Apply(ToolStripItemCollection items)
{
int lastGroup = -1;
foreach (MergableItem item in List)
{
if (item.Group != lastGroup && lastGroup > -1)
items.Add(new ToolStripSeparator());
items.Add(item.Apply());
lastGroup = item.Group;
}
}
示例7: CreateButton
private static void CreateButton(ToolStripItemCollection items, string title, EventHandler handler,
Workitem item)
{
var button = new ToolStripMenuItem(title, null, handler);
items.Add(button);
button.Tag = item;
}
示例8: Sort
public static void Sort(ToolStripItemCollection collection, IComparer comparer)
{
ArrayList items = new ArrayList(collection);
items.Sort(comparer);
collection.Clear();
foreach (object itm in items)
collection.Add(itm as ToolStripItem);
}
示例9: GetNamedChild
ToolStripMenuItem GetNamedChild(ToolStripItemCollection container, string name)
{
foreach (ToolStripMenuItem item in container)
if (name == item.Text)
return item as ToolStripMenuItem;
ToolStripMenuItem newItem = new ToolStripMenuItem(name);
container.Add(newItem);
return newItem;
}
示例10: InsertTemplate
/// <summary>
/// Add template to a specific list
/// </summary>
/// <param name="collection">List, where to add template</param>
/// <param name="template">Template to add</param>
/// <param name="onClick">Click handlers</param>
public static void InsertTemplate(ToolStripItemCollection collection, MoneyDataSet.TransactionTemplatesRow template, EventHandler onClick)
{
Image image = null;
if (template.ID.Equals(MoneyDataSet.IDs.TransactionTemplates.Transfer))
{
image = Properties.Resources.table_relationship;
}
ToolStripMenuItem tsmiFromTemplate = new ToolStripMenuItem(template.Title, image, onClick);
tsmiFromTemplate.Tag = template;
tsmiFromTemplate.ToolTipText = template.Message;
collection.Add(tsmiFromTemplate);
}
示例11: AddItemsToMenu
static void AddItemsToMenu(ToolStripItemCollection collection, IEnumerable<MenuItemDescriptor> descriptors)
{
foreach (MenuItemDescriptor descriptor in descriptors) {
object item = CreateMenuItemFromDescriptor(descriptor);
if (item is ToolStripItem) {
collection.Add((ToolStripItem)item);
if (item is IStatusUpdate)
((IStatusUpdate)item).UpdateStatus();
} else {
IMenuItemBuilder submenuBuilder = (IMenuItemBuilder)item;
collection.AddRange(submenuBuilder.BuildItems(descriptor.Codon, descriptor.Parameter).Cast<ToolStripItem>().ToArray());
}
}
}
示例12: FillMenuItems
/// <summary>
/// Fills items to the specified tool strip item collection
/// </summary>
public static void FillMenuItems(ToolStripItemCollection items, XmlNode node)
{
switch (node.Name)
{
case "menu" :
String name = XmlHelper.GetAttribute(node, "name");
if (name == "SyntaxMenu") node.InnerXml = GetSyntaxMenuXml();
items.Add(GetMenu(node));
break;
case "separator" :
items.Add(GetSeparator(node));
break;
case "button" :
ToolStripMenuItem menu = GetMenuItem(node);
items.Add(menu); // Add menu first to get the id correct
String id = GetMenuItemId(menu);
if (id.IndexOf('.') > -1)
{
Globals.MainForm.RegisterShortcutItem(GetMenuItemId(menu), menu);
}
break;
}
}
示例13: AddItemsToMenu
public static void AddItemsToMenu(ToolStripItemCollection collection, object owner, string addInTreePath)
{
ArrayList buildItems = AddInTree.GetTreeNode(addInTreePath).BuildChildItems(owner);
foreach (object item in buildItems) {
if (item is ToolStripItem) {
collection.Add((ToolStripItem)item);
if (item is IStatusUpdate)
((IStatusUpdate)item).UpdateStatus();
} else {
ISubmenuBuilder submenuBuilder = (ISubmenuBuilder)item;
collection.AddRange(submenuBuilder.BuildSubmenu(null, owner));
}
}
}
示例14: AddItemsToMenu
static void AddItemsToMenu(ToolStripItemCollection collection, List<MenuItemDescriptor> descriptors)
{
foreach (MenuItemDescriptor descriptor in descriptors) {
object item = CreateMenuItemFromDescriptor(descriptor);
if (item is ToolStripItem) {
collection.Add((ToolStripItem)item);
if (item is IStatusUpdate)
((IStatusUpdate)item).UpdateStatus();
} else {
ISubmenuBuilder submenuBuilder = (ISubmenuBuilder)item;
collection.AddRange(submenuBuilder.BuildSubmenu(descriptor.Codon, descriptor.Caller));
}
}
}
示例15: addSaveSlots
private void addSaveSlots(ToolStripItemCollection items)
{
//test(mnuSaveSlots.DropDownItems);
ToolStripMenuItem mnuAll = new ToolStripMenuItem();
//
// mnuAll
//
mnuAll.Name = "mnuAll";
mnuAll.Size = new System.Drawing.Size(152, 22);
mnuAll.Text = "All";
mnuAll.Click += new EventHandler(this.mnuAll_Click);
items.Add(mnuAll);
for (int i = 1; i <= 20; i++)
{
ToolStripMenuItem mnuSlot;
mnuSlot = new ToolStripMenuItem();
mnuSlot.Name = "mnuSlot" + i;
mnuSlot.Size = new System.Drawing.Size(152, 22);
mnuSlot.Text = "Slot " + i;
mnuSlot.Click += new System.EventHandler(this.mnuSlot_Click);
items.Add(mnuSlot);
}
}