ToolStripManager.Merge 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
結合 ToolStrip 控制。
多載
| 名稱 | Description |
|---|---|
| Merge(ToolStrip, String) |
結合兩個 ToolStrip 同類型的物件。 |
| Merge(ToolStrip, ToolStrip) |
結合了兩種 ToolStrip 不同類型的物品。 |
Merge(ToolStrip, String)
結合兩個 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
參數
傳回
true若合併成功;否則,。 false
例外狀況
sourceToolStrip 或 targetName 為 null。
sourceToolStrip 或 targetName 指的是相同的 ToolStrip。
備註
使用此 ToolStripManager.Merge 方法將相同類型的物件結合 ToolStrip ,例如 ToolStrip 物件與其他 ToolStrip 物件、 MenuStrip 物件與其他 MenuStrip 物件,等等。
用這個 ToolStripManager.Merge 方法來組合 ToolStrip 不同類型的物件。
ToolStrip.AllowMerge屬性必須對兩個ToolStrip物件都設定為 ,true且來源型別與目標型別必須相同,否則此方法會回傳 false。
備註
若 MDI 子表單有兩個 MenuStrip 控制項,將父表單設 IsMdiContainer 為 時 true ,僅合併其中一個 MenuStrip 控制項的內容。 用於 Merge 合併 MDI 父表單中其他子 MenuStrip 控制項的內容。
另請參閱
適用於
Merge(ToolStrip, ToolStrip)
結合了兩種 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
參數
傳回
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 ,例如 ToolStrip 物件與其他 ToolStrip 物件、 MenuStrip 物件與其他 MenuStrip 物件,等等。
ToolStrip.AllowMerge該屬性必須對兩個ToolStrip物件都設定為 ,true否則此方法會回傳 false。
備註
若 MDI 子表單有兩個 MenuStrip 控制項,將父表單設 IsMdiContainer 為 時 true ,僅合併其中一個 MenuStrip 控制項的內容。 用於 Merge 合併 MDI 父表單中其他子 MenuStrip 控制項的內容。