本文整理汇总了C#中System.Windows.Forms.ToolStripMenuItem.?.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ToolStripMenuItem.?.Dispose方法的具体用法?C# ToolStripMenuItem.?.Dispose怎么用?C# ToolStripMenuItem.?.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ToolStripMenuItem
的用法示例。
在下文中一共展示了ToolStripMenuItem.?.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShowCalendarContextMenu
/// <summary>
/// Show the context menu for the given day
/// </summary>
/// <param name="datetime"></param>
/// <param name="location"></param>
private void ShowCalendarContextMenu(DateTime datetime, Point location)
{
// Remove old submenus
while (calContext.Items.Count > 2)
{
calContext.Items.RemoveAt(2);
}
// Set date Tag to new entry
calContext.Items[0].Tag = datetime;
// Add "Edit" menus for every schedule on this day
foreach (ScheduleEntry entry in Scheduler.Entries.Where(x => x.IsToday(datetime)))
{
ToolStripItem tempItem = null;
try
{
tempItem = new ToolStripMenuItem();
tempItem.Click += editMenuItem_Click;
tempItem.Text = $"Edit \"{entry.Title}\"...";
tempItem.Tag = entry;
ToolStripItem item = tempItem;
tempItem = null;
calContext.Items.Add(item);
}
finally
{
tempItem?.Dispose();
}
}
// Show the toolstrip seperator if there are any entries
toolStripSeperator.Visible = calContext.Items.Count > 2;
// Display the menu
calContext.Show(calControl, location);
}
示例2: BuildContextMenu
/// <summary>
/// Builds the context menu for the selected skill.
/// </summary>
/// <param name="skill">The skill.</param>
private void BuildContextMenu(Skill skill)
{
tsmiAddSkill.DropDownItems.Clear();
if (skill == null || skill.Level == 5)
{
tsmiAddSkill.Text = String.Empty;
return;
}
// Reset the menu
tsmiAddSkill.Text = $"Add {skill.Name}";
// Build the level options
for (Int64 level = skill.Level + 1; level <= 5; level++)
{
ToolStripMenuItem tempMenuLevel = null;
try
{
tempMenuLevel = new ToolStripMenuItem($"Level {Skill.GetRomanFromInt(level)} to");
Character.Plans.AddTo(tempMenuLevel.DropDownItems,
(menuPlanItem, plan) =>
{
menuPlanItem.Click += menuPlanItem_Click;
menuPlanItem.Tag = new KeyValuePair<Plan, SkillLevel>(plan, new SkillLevel(skill, level));
});
ToolStripMenuItem menuLevel = tempMenuLevel;
tempMenuLevel = null;
tsmiAddSkill.DropDownItems.Add(menuLevel);
}
finally
{
tempMenuLevel?.Dispose();
}
}
}
示例3: CreateNewMonitorToolStripMenuItem
/// <summary>
/// Creates the new monitor toolstrip menu item.
/// </summary>
/// <param name="monitor">The monitor.</param>
/// <returns>New menu item for a monitor.</returns>
private static ToolStripMenuItem CreateNewMonitorToolStripMenuItem(IQueryMonitor monitor)
{
string menuText = $"Update {monitor} {GenerateTimeToNextUpdateText(monitor)}";
ToolStripMenuItem menu;
ToolStripMenuItem tempMenu = null;
try
{
tempMenu = new ToolStripMenuItem(menuText)
{
Tag = monitor.Method,
Enabled = monitor.Enabled && monitor.HasAccess && monitor.CanForceUpdate
};
menu = tempMenu;
tempMenu = null;
}
finally
{
tempMenu?.Dispose();
}
return menu;
}