ToolStripManager.RevertMerge 方法

定义

撤消两个 ToolStrip 对象的合并。

重载

RevertMerge(String)

撤消两个 ToolStrip 对象的合并,将具有指定名称的 ToolStrip 还原到合并之前的状态,并使以前的所有合并操作无效。

RevertMerge(ToolStrip)

撤消两个 ToolStrip 对象的合并,将指定的 ToolStrip 还原到合并之前的状态,并使以前的所有合并操作无效。

RevertMerge(ToolStrip, ToolStrip)

撤消两个 ToolStrip 对象的合并,将两个 ToolStrip 控件还原到合并前的状态,并取消以前的所有合并操作。

RevertMerge(String)

撤消两个 ToolStrip 对象的合并,将具有指定名称的 ToolStrip 还原到合并之前的状态,并使以前的所有合并操作无效。

public:
 static bool RevertMerge(System::String ^ targetName);
public static bool RevertMerge (string targetName);
static member RevertMerge : string -> bool
Public Shared Function RevertMerge (targetName As String) As Boolean

参数

targetName
String

要撤消其合并操作的 ToolStripItem 的名称。

返回

Boolean

如果合并操作撤消成功,则为 true;否则为 false

注解

必须为ToolStrip.AllowMerge这两个ToolStrip对象设置true该属性,否则此方法返回false

另请参阅

适用于

RevertMerge(ToolStrip)

撤消两个 ToolStrip 对象的合并,将指定的 ToolStrip 还原到合并之前的状态,并使以前的所有合并操作无效。

public:
 static bool RevertMerge(System::Windows::Forms::ToolStrip ^ targetToolStrip);
public static bool RevertMerge (System.Windows.Forms.ToolStrip targetToolStrip);
static member RevertMerge : System.Windows.Forms.ToolStrip -> bool
Public Shared Function RevertMerge (targetToolStrip As ToolStrip) As Boolean

参数

targetToolStrip
ToolStrip

要撤消合并操作的 ToolStripItem

返回

Boolean

如果合并操作撤消成功,则为 true;否则为 false

示例

下面的代码示例撤消菜单项的合并。 此示例是类概述中提供的大型示例的 ToolStripManager 一部分。

private MergeSample CurrentSample
{
    get { return currentSample; }
    set
    {
        if (currentSample != value)
        {
            bool resetRequired = false;

            if (currentSample == MergeSample.MatchOnly)
            {
                resetRequired = true;
            }
            currentSample = value;
            // Undo previous merge, if any.
            ToolStripManager.RevertMerge(cmsBase, cmsItemsToMerge);
            if (resetRequired)
            {
                RebuildItemsToMerge();
            }

            switch (currentSample)
            {
                case MergeSample.None:
                    return;
                case MergeSample.Append:
                    ScenarioText = "This sample adds items to the end of the list using MergeAction.Append.\r\n\r\nThis is the default setting for MergeAction. A typical scenario is adding menu items to the end of the menu when some part of the program is activated.";
                    ShowAppendSample();
                    break;
                case MergeSample.InsertInSameLocation:
                    ScenarioText = "This sample adds items to the middle of the list using MergeAction.Insert.\r\n\r\nNotice here how the items are added in reverse order: four, three, two, one. This is because they all have the same merge index.\r\n\r\nA typical scenario is adding menu items to the middle or beginning of the menu when some part of the program is activated. ";
                    ShowInsertInSameLocationSample();
                    break;
                case MergeSample.InsertInSameLocationPreservingOrder:
                    ScenarioText = "This sample is the same as InsertInSameLocation, except the items are added in normal order by increasing the MergeIndex of \"two merged items\" to be 3, \"three merged items\" to be 5, and so on.\r\n  You could also add the original items backwards to the source ContextMenuStrip.";
                    ShowInsertInSameLocationPreservingOrderSample();
                    break;
                case MergeSample.ReplacingItems:
                    ScenarioText = "This sample replaces a menu item using MergeAction.Replace. Use this for the MDI scenario where saving does something completely different.\r\n\r\nMatching is based on the Text property. If there is no text match, merging reverts to MergeIndex.";
                    ShowReplaceSample();
                    break;
                case MergeSample.MatchOnly:
                    ScenarioText = "This sample adds only the subitems from the child to the target ContextMenuStrip.";
                    ShowMatchOnlySample();
                    break;
            }
            // Reapply with the new settings.
            ToolStripManager.Merge(cmsItemsToMerge, cmsBase);
        }
    }
}

Private Property CurrentSample() As MergeSample
   Get
      Return currentSample1
   End Get
   Set
      If currentSample1 <> value Then
         Dim resetRequired As Boolean = False
         
         If currentSample1 = MergeSample.MatchOnly Then
            resetRequired = True
         End If
         currentSample1 = value
         ' Undo previous merge, if any.
         ToolStripManager.RevertMerge(cmsBase, cmsItemsToMerge)
         If resetRequired Then
            RebuildItemsToMerge()
         End If
         
         Select Case currentSample1
            Case MergeSample.None
                  Return
            Case MergeSample.Append
               ScenarioText = "This sample adds items to the end of the list using MergeAction.Append." + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf + "This is the default setting for MergeAction. A typical scenario is adding menu items to the end of the menu when some part of the program is activated."
               ShowAppendSample()
            Case MergeSample.InsertInSameLocation
               ScenarioText = "This sample adds items to the middle of the list using MergeAction.Insert." + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf + "Notice here how the items are added in reverse order: four, three, two, one. This is because they all have the same merge index." + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf + "A typical scenario is adding menu items to the middle or beginning of the menu when some part of the program is activated. "
               ShowInsertInSameLocationSample()
            Case MergeSample.InsertInSameLocationPreservingOrder
               ScenarioText = "This sample is the same as InsertInSameLocation, except the items are added in normal order by increasing the MergeIndex of ""two merged items"" to be 3, ""three merged items"" to be 5, and so on." + ControlChars.Cr + ControlChars.Lf + "  You could also add the original items backwards to the source ContextMenuStrip."
               ShowInsertInSameLocationPreservingOrderSample()
            Case MergeSample.ReplacingItems
               ScenarioText = "This sample replaces a menu item using MergeAction.Replace. Use this for the MDI scenario where saving does something completely different." + ControlChars.Cr + ControlChars.Lf + ControlChars.Cr + ControlChars.Lf + "Matching is based on the Text property. If there is no text match, merging reverts to MergeIndex."
               ShowReplaceSample()
            Case MergeSample.MatchOnly
               ScenarioText = "This sample adds only the subitems from the child to the target ContextMenuStrip."
               ShowMatchOnlySample()
         End Select
         
         ' Reapply with the new settings.
         ToolStripManager.Merge(cmsItemsToMerge, cmsBase)
      End If
   End Set
End Property

注解

必须为ToolStrip.AllowMerge这两个ToolStrip对象设置true该属性,否则此方法返回false

另请参阅

适用于

RevertMerge(ToolStrip, ToolStrip)

撤消两个 ToolStrip 对象的合并,将两个 ToolStrip 控件还原到合并前的状态,并取消以前的所有合并操作。

public:
 static bool RevertMerge(System::Windows::Forms::ToolStrip ^ targetToolStrip, System::Windows::Forms::ToolStrip ^ sourceToolStrip);
public static bool RevertMerge (System.Windows.Forms.ToolStrip targetToolStrip, System.Windows.Forms.ToolStrip sourceToolStrip);
static member RevertMerge : System.Windows.Forms.ToolStrip * System.Windows.Forms.ToolStrip -> bool
Public Shared Function RevertMerge (targetToolStrip As ToolStrip, sourceToolStrip As ToolStrip) As Boolean

参数

targetToolStrip
ToolStrip

要撤消其合并操作的 ToolStripItem 的名称。

sourceToolStrip
ToolStrip

已经与 targetToolStrip 合并的 ToolStrip

返回

Boolean

如果合并操作撤消成功,则为 true;否则为 false

例外

sourceToolStripnull

注解

必须为这两个ToolStrip对象设置trueToolStrip.AllowMerge属性,否则此方法返回 false

适用于