ToolStripManager.Merge Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Combine des ToolStrip contrôles.
Surcharges
| Nom | Description |
|---|---|
| Merge(ToolStrip, String) |
Combine deux ToolStrip objets du même type. |
| Merge(ToolStrip, ToolStrip) |
Combine deux ToolStrip objets de types différents. |
Merge(ToolStrip, String)
- Source:
- ToolStripManager.cs
- Source:
- ToolStripManager.cs
- Source:
- ToolStripManager.cs
- Source:
- ToolStripManager.cs
- Source:
- ToolStripManager.cs
Combine deux ToolStrip objets du même type.
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
Paramètres
- sourceToolStrip
- ToolStrip
À ToolStrip combiner avec le ToolStrip référencé par le targetName paramètre.
- targetName
- String
Nom du ToolStrip fichier qui reçoit le ToolStrip nom référencé par le sourceToolStrip paramètre.
Retours
true si la fusion réussit ; sinon, false.
Exceptions
sourceToolStrip ou targetName est null.
sourceToolStrip ou targetName faire référence au même ToolStrip.
Remarques
Utilisez la ToolStripManager.Merge méthode pour combiner ToolStrip des objets de type identique, tels que ToolStrip des objets avec d’autres ToolStrip objets, MenuStrip des objets avec d’autres MenuStrip objets, etc.
Utilisez la ToolStripManager.Merge méthode pour combiner ToolStrip des objets de différents types.
La ToolStrip.AllowMerge propriété doit être définie true pour les deux ToolStrip objets, et les types source et cible doivent être identiques, ou cette méthode retourne false.
Note
S’il existe deux MenuStrip contrôles sur un formulaire enfant MDI, la définition de true la valeur IsMdiContainer pour le formulaire parent fusionne le contenu d’un seul des MenuStrip contrôles. Permet Merge de fusionner le contenu des contrôles enfants MenuStrip supplémentaires sur le formulaire parent MDI.
Voir aussi
S’applique à
Merge(ToolStrip, ToolStrip)
- Source:
- ToolStripManager.cs
- Source:
- ToolStripManager.cs
- Source:
- ToolStripManager.cs
- Source:
- ToolStripManager.cs
- Source:
- ToolStripManager.cs
Combine deux ToolStrip objets de types différents.
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
Paramètres
- sourceToolStrip
- ToolStrip
À ToolStrip combiner avec le ToolStrip référencé par le targetToolStrip paramètre.
- targetToolStrip
- ToolStrip
Qui ToolStrip reçoit le ToolStrip référencé par le sourceToolStrip paramètre.
Retours
true si la fusion réussit ; sinon, false.
Exemples
L’exemple de code suivant fusionne les éléments de menu en fonction des choix spécifiés. Cet exemple fait partie d’un exemple plus large disponible dans la vue d’ensemble de la ToolStripManager classe.
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
Remarques
Utilisez la ToolStripManager.Merge méthode pour combiner ToolStrip des objets de différents types.
Utilisez la ToolStripManager.Merge méthode pour combiner ToolStrip des objets de type identique, tels que ToolStrip des objets avec d’autres ToolStrip objets, MenuStrip des objets avec d’autres MenuStrip objets, etc.
La ToolStrip.AllowMerge propriété doit être définie true pour les deux ToolStrip objets, ou cette méthode retourne false.
Note
S’il existe deux MenuStrip contrôles sur un formulaire enfant MDI, la définition de true la valeur IsMdiContainer pour le formulaire parent fusionne le contenu d’un seul des MenuStrip contrôles. Permet Merge de fusionner le contenu des contrôles enfants MenuStrip supplémentaires sur le formulaire parent MDI.