ToolStripManager.Merge メソッド

定義

ToolStrip コントロールを結合します。

オーバーロード

Merge(ToolStrip, String)

同じ型の 2 つの ToolStrip オブジェクトを結合します。

Merge(ToolStrip, ToolStrip)

異なる型の 2 つの ToolStrip オブジェクトを結合します。

Merge(ToolStrip, String)

同じ型の 2 つの ToolStrip オブジェクトを結合します。

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

パラメーター

sourceToolStrip
ToolStrip

targetName パラメーターで参照される ToolStrip に対して結合される ToolStrip

targetName
String

sourceToolStrip パラメーターで参照される ToolStrip を受け取る ToolStrip の名前。

戻り値

Boolean

マージが成功した場合は true。それ以外の場合は false

例外

sourceToolStrip または targetNamenull です。

sourceToolStrip または targetName が同じ ToolStrip を参照します。

注釈

このメソッドをToolStripManager.Merge使用して、同じ型のオブジェクト (オブジェクトと他のオブジェクト、他ToolStripのオブジェクトMenuStripを含MenuStripむオブジェクトなどToolStrip) を結合ToolStripします。

このメソッドを ToolStripManager.Merge 使用して、さまざまな型のオブジェクトを結合 ToolStrip します。

プロパティはToolStrip.AllowMerge両方ToolStripのオブジェクトに対して設定するtrue必要があり、ソースとターゲットの型は同じである必要があります。または、このメソッドは返しますfalse

注意

MDI 子フォームに 2 つのMenuStripコントロールがある場合、親フォームに設定するとtrueIsMdiContainerコントロールの 1 つだけの内容がMenuStripマージされます。 MDI 親フォームの追加の子MenuStripコントロールの内容をマージするために使用Mergeします。

こちらもご覧ください

適用対象

Merge(ToolStrip, ToolStrip)

異なる型の 2 つの ToolStrip オブジェクトを結合します。

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

パラメーター

sourceToolStrip
ToolStrip

targetToolStrip パラメーターで参照される ToolStrip に対して結合される ToolStrip

targetToolStrip
ToolStrip

sourceToolStrip パラメーターで参照される ToolStrip を受け取る ToolStrip

戻り値

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

注釈

このメソッドを ToolStripManager.Merge 使用して、さまざまな型のオブジェクトを結合 ToolStrip します。

このメソッドをToolStripManager.Merge使用して、同じ型のオブジェクト (オブジェクトと他のオブジェクト、他ToolStripのオブジェクトMenuStripを含MenuStripむオブジェクトなどToolStrip) を結合ToolStripします。

プロパティはToolStrip.AllowMerge両方ToolStripのオブジェクトに対してtrue設定する必要があります。または、このメソッドが返しますfalse

注意

MDI 子フォームに 2 つのMenuStripコントロールがある場合、親フォームに設定するとtrueIsMdiContainerコントロールの 1 つだけの内容がMenuStripマージされます。 MDI 親フォームの追加の子MenuStripコントロールの内容をマージするために使用Mergeします。

こちらもご覧ください

適用対象