本文整理汇总了C#中System.Windows.Forms.ToolStrip.BeginMerge方法的典型用法代码示例。如果您正苦于以下问题:C# ToolStrip.BeginMerge方法的具体用法?C# ToolStrip.BeginMerge怎么用?C# ToolStrip.BeginMerge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ToolStrip
的用法示例。
在下文中一共展示了ToolStrip.BeginMerge方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Merge
public static bool Merge (ToolStrip sourceToolStrip, ToolStrip targetToolStrip)
{
// Check for exceptions
if (sourceToolStrip == null)
throw new ArgumentNullException ("sourceToolStrip");
if (targetToolStrip == null)
throw new ArgumentNullException ("targetName");
if (targetToolStrip == sourceToolStrip)
throw new ArgumentException ("Source and target ToolStrip must be different.");
// If the toolstrips don't allow merging, don't merge them
if (!sourceToolStrip.AllowMerge || !targetToolStrip.AllowMerge)
return false;
// We currently can't support merging multiple times
if (sourceToolStrip.IsCurrentlyMerged || targetToolStrip.IsCurrentlyMerged)
return false;
// What I wouldn't give to be able to modify a collection
// while enumerating through it...
List<ToolStripItem> items_to_move = new List<ToolStripItem> ();
// Create a list of every ToolStripItem we plan on moving
foreach (ToolStripItem tsi in sourceToolStrip.Items) {
switch (tsi.MergeAction) {
case MergeAction.Append:
default:
items_to_move.Add (tsi);
break;
case MergeAction.Insert:
if (tsi.MergeIndex >= 0)
items_to_move.Add (tsi);
break;
case MergeAction.Replace:
case MergeAction.Remove:
case MergeAction.MatchOnly:
foreach (ToolStripItem target_tsi in targetToolStrip.Items)
if (tsi.Text == target_tsi.Text) {
items_to_move.Add (tsi);
break;
}
break;
}
}
// If there was nothing valid to merge, return false
if (items_to_move.Count == 0)
return false;
// Set some state so we can unmerge later
sourceToolStrip.BeginMerge ();
targetToolStrip.BeginMerge ();
sourceToolStrip.SuspendLayout ();
targetToolStrip.SuspendLayout ();
while (items_to_move.Count > 0) {
ToolStripItem tsi = items_to_move[0];
items_to_move.Remove (tsi);
switch (tsi.MergeAction) {
case MergeAction.Append:
default:
// Just changing the parent will append it to the target
// and remove it from the source
ToolStrip.SetItemParent (tsi, targetToolStrip);
break;
case MergeAction.Insert:
// Do the same work as Append, except Insert it into the
// location specified by the MergeIndex
RemoveItemFromParentToolStrip (tsi);
if (tsi.MergeIndex == -1)
continue;
else if (tsi.MergeIndex >= CountRealToolStripItems (targetToolStrip))
targetToolStrip.Items.AddNoOwnerOrLayout (tsi);
else
targetToolStrip.Items.InsertNoOwnerOrLayout (AdjustItemMergeIndex (targetToolStrip, tsi), tsi);
tsi.Parent = targetToolStrip;
break;
case MergeAction.Replace:
// Find a target ToolStripItem with the same Text, remove it
// and replace it with the source one
foreach (ToolStripItem target_tsi in targetToolStrip.Items)
if (tsi.Text == target_tsi.Text) {
RemoveItemFromParentToolStrip (tsi);
// Insert where the old one is, then remove the old one
targetToolStrip.Items.InsertNoOwnerOrLayout (targetToolStrip.Items.IndexOf (target_tsi), tsi);
targetToolStrip.Items.RemoveNoOwnerOrLayout (target_tsi);
// Store the replaced one so we can get it back in unmerge
targetToolStrip.HiddenMergedItems.Add (target_tsi);
break;
//.........这里部分代码省略.........