Share via


ControlCollection.AddDatePickerContentControl Méthode

Définition

Surcharges

AddDatePickerContentControl(String)

Ajoute un nouveau DatePickerContentControl à la sélection actuelle dans le document.

AddDatePickerContentControl(ContentControl, String)

Ajoute un nouveau DatePickerContentControl à la collection. Le nouveau contrôle est basé sur un contrôle de contenu natif qui figure déjà dans le document.

AddDatePickerContentControl(Range, String)

Ajoute un nouveau DatePickerContentControl à la plage spécifiée dans le document.

AddDatePickerContentControl(String)

Ajoute un nouveau DatePickerContentControl à la sélection actuelle dans le document.

public:
 Microsoft::Office::Tools::Word::DatePickerContentControl ^ AddDatePickerContentControl(System::String ^ name);
public Microsoft.Office.Tools.Word.DatePickerContentControl AddDatePickerContentControl (string name);
abstract member AddDatePickerContentControl : string -> Microsoft.Office.Tools.Word.DatePickerContentControl
Public Function AddDatePickerContentControl (name As String) As DatePickerContentControl

Paramètres

name
String

Nom du nouveau contrôle.

Retours

DatePickerContentControl qui a été ajouté au document.

Exceptions

name a la valeur null ou est de longueur nulle.

Un contrôle du même nom se trouve déjà dans la ControlCollection.

Exemples

L’exemple de code suivant ajoute un nouveau DatePickerContentControl au début du document. L’exemple modifie également le format dans lequel le contrôle affiche les dates.

Cette version est destinée à une personnalisation au niveau du document. Pour utiliser ce code, collez-le dans la ThisDocument classe de votre projet et appelez la AddDatePickerControlAtSelection méthode à partir de la ThisDocument_Startup méthode .

private Microsoft.Office.Tools.Word.DatePickerContentControl datePickerControl1;

private void AddDatePickerControlAtSelection()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    this.Paragraphs[1].Range.Select();

    datePickerControl1 = this.Controls.AddDatePickerContentControl("datePickerControl1");
    datePickerControl1.DateDisplayFormat = "MMMM d, yyyy";
    datePickerControl1.PlaceholderText = "Choose a date";
}
Dim datePickerControl1 As Microsoft.Office.Tools.Word.DatePickerContentControl

Private Sub AddDatePickerControlAtSelection()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Me.Paragraphs(1).Range.Select()
    datePickerControl1 = Me.Controls.AddDatePickerContentControl("datePickerControl1")
    datePickerControl1.DateDisplayFormat = "MMMM d, yyyy"
    datePickerControl1.PlaceholderText = "Choose a date"
End Sub

Cette version concerne un complément au niveau de l’application qui cible .NET Framework 4 ou .NET Framework 4.5. Pour utiliser ce code, collez-le dans la ThisAddIn classe de votre projet et appelez la AddDatePickerControlAtSelection méthode à partir de la ThisAddIn_Startup méthode .

private Microsoft.Office.Tools.Word.DatePickerContentControl datePickerControl1;

private void AddDatePickerControlAtSelection()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();
    vstoDoc.Paragraphs[1].Range.Select();

    datePickerControl1 = vstoDoc.Controls.AddDatePickerContentControl("datePickerControl1");
    datePickerControl1.DateDisplayFormat = "MMMM d, yyyy";
    datePickerControl1.PlaceholderText = "Choose a date";
}
Dim datePickerControl1 As Microsoft.Office.Tools.Word.DatePickerContentControl

Private Sub AddDatePickerControlAtSelection()
    If Me.Application.ActiveDocument Is Nothing Then
        Return
    End If

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
    vstoDoc.Paragraphs(1).Range.Select()
    datePickerControl1 = vstoDoc.Controls.AddDatePickerContentControl("datePickerControl1")
    datePickerControl1.DateDisplayFormat = "MMMM d, yyyy"
    datePickerControl1.PlaceholderText = "Choose a date"
End Sub

Remarques

Utilisez cette méthode pour ajouter un nouveau DatePickerContentControl à la sélection actuelle dans le document au moment de l’exécution. Pour plus d'informations, consultez Adding Controls to Office Documents at Run Time.

S’applique à

AddDatePickerContentControl(ContentControl, String)

Ajoute un nouveau DatePickerContentControl à la collection. Le nouveau contrôle est basé sur un contrôle de contenu natif qui figure déjà dans le document.

public:
 Microsoft::Office::Tools::Word::DatePickerContentControl ^ AddDatePickerContentControl(Microsoft::Office::Interop::Word::ContentControl ^ contentControl, System::String ^ name);
public Microsoft.Office.Tools.Word.DatePickerContentControl AddDatePickerContentControl (Microsoft.Office.Interop.Word.ContentControl contentControl, string name);
abstract member AddDatePickerContentControl : Microsoft.Office.Interop.Word.ContentControl * string -> Microsoft.Office.Tools.Word.DatePickerContentControl
Public Function AddDatePickerContentControl (contentControl As ContentControl, name As String) As DatePickerContentControl

Paramètres

contentControl
ContentControl

ContentControl qui est la base du nouveau contrôle.

name
String

Nom du nouveau contrôle.

Retours

DatePickerContentControl qui a été ajouté au document.

Exceptions

contentControl est null.-or- name est ou n’a null aucune longueur.

Un contrôle du même nom se trouve déjà dans la ControlCollection.

contentControln’est pas une galerie de blocs de construction (autrement dit, la Type propriété de contentControl n’a pas la valeur Microsoft.Office.Interop.Word. WdContentControlType.wdContentControlDate).

Exemples

L’exemple de code suivant crée un nouveau DatePickerContentControl pour chaque contrôle de date natif qui se trouve dans le document.

Cette version est destinée à une personnalisation au niveau du document. Pour utiliser ce code, collez-le dans la ThisDocument classe de votre projet et appelez la CreateDatePickerControlsFromNativeControls méthode à partir de la ThisDocument_Startup méthode .

private System.Collections.Generic.List
    <Microsoft.Office.Tools.Word.DatePickerContentControl> datePickerControls;

private void CreateDatePickerControlsFromNativeControls()
{
    datePickerControls = new System.Collections.Generic.List
        <Microsoft.Office.Tools.Word.DatePickerContentControl>();
    int count = 0;

    foreach (Word.ContentControl nativeControl in this.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlDate)
        {
            count++;
            Microsoft.Office.Tools.Word.DatePickerContentControl tempControl =
                this.Controls.AddDatePickerContentControl(nativeControl,
                "VSTODatePickerContentControl" + count.ToString());
            datePickerControls.Add(tempControl);
        }
    }
}
Private datePickerControls As New System.Collections.Generic.List _
        (Of Microsoft.Office.Tools.Word.DatePickerContentControl)

Private Sub CreateDatePickerControlsFromNativeControls()
    If Me.ContentControls.Count <= 0 Then
        Return
    End If

    Dim count As Integer = 0
    For Each nativeControl As Word.ContentControl In Me.ContentControls
        If nativeControl.Type = Word.WdContentControlType.wdContentControlDate Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.DatePickerContentControl = _
                Me.Controls.AddDatePickerContentControl(nativeControl, _
                "VSTODatePickerContentControl" + count.ToString())
            datePickerControls.Add(tempControl)
        End If
    Next nativeControl
End Sub

Cette version concerne un complément au niveau de l’application qui cible .NET Framework 4 ou .NET Framework 4.5. Pour utiliser ce code, collez-le dans la ThisAddIn classe de votre projet et appelez la CreateDatePickerControlsFromNativeControls méthode à partir de la ThisAddIn_Startup méthode .

private System.Collections.Generic.List
    <Microsoft.Office.Tools.Word.DatePickerContentControl> datePickerControls;

private void CreateDatePickerControlsFromNativeControls()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    datePickerControls = new System.Collections.Generic.List
        <Microsoft.Office.Tools.Word.DatePickerContentControl>();
    int count = 0;

    foreach (Word.ContentControl nativeControl in vstoDoc.ContentControls)
    {
        if (nativeControl.Type == Word.WdContentControlType.wdContentControlDate)
        {
            count++;
            Microsoft.Office.Tools.Word.DatePickerContentControl tempControl =
                vstoDoc.Controls.AddDatePickerContentControl(nativeControl,
                "VSTODatePickerContentControl" + count.ToString());
            datePickerControls.Add(tempControl);
        }
    }
}
Private datePickerControls As New System.Collections.Generic.List _
        (Of Microsoft.Office.Tools.Word.DatePickerContentControl)

Private Sub CreateDatePickerControlsFromNativeControls()
    If Me.Application.ActiveDocument Is Nothing Then
        Return
    End If

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    If vstoDoc.ContentControls.Count <= 0 Then
        Return
    End If

    Dim count As Integer = 0
    For Each nativeControl As Word.ContentControl In vstoDoc.ContentControls
        If nativeControl.Type = Word.WdContentControlType.wdContentControlDate Then
            count += 1
            Dim tempControl As Microsoft.Office.Tools.Word.DatePickerContentControl = _
                vstoDoc.Controls.AddDatePickerContentControl(nativeControl, _
                "VSTODatePickerContentControl" + count.ToString())
            datePickerControls.Add(tempControl)
        End If
    Next nativeControl
End Sub

L’exemple de code suivant crée un nouveau DatePickerContentControl pour chaque contrôle de date natif que l’utilisateur ajoute au document.

Cette version est destinée à une personnalisation au niveau du document. Pour utiliser ce code, collez-le dans la ThisDocument classe de votre projet. En C#, vous devez également attacher le ThisDocument_DatePickerContentControlAfterAdd gestionnaire d'événements ContentControlAfterAdd à l'événement ThisDocument .

void ThisDocument_DatePickerContentControlAfterAdd(Word.ContentControl NewContentControl, bool InUndoRedo)
{
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlDate)
    {
        this.Controls.AddDatePickerContentControl(NewContentControl,
            "DatePickerControl" + NewContentControl.ID);
    }
}
Private Sub ThisDocument_DatePickerContentControlAfterAdd(ByVal NewContentControl As Word.ContentControl, _
    ByVal InUndoRedo As Boolean) Handles Me.ContentControlAfterAdd

    If NewContentControl.Type = Word.WdContentControlType.wdContentControlDate Then
        Me.Controls.AddDatePickerContentControl(NewContentControl, _
            "DatePickerControl" + NewContentControl.ID)
    End If
End Sub

Pour utiliser ce code, collez-le dans la ThisAddIn classe de votre projet. En outre, vous devez attacher le ActiveDocument_DatePickerContentControlAfterAdd gestionnaire d’événements à l’événement ContentControlAfterAdd du document actif.

void ActiveDocument_DatePickerContentControlAfterAdd(
    Word.ContentControl NewContentControl, bool InUndoRedo)
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    if (NewContentControl.Type == Word.WdContentControlType.wdContentControlDate)
    {
        vstoDoc.Controls.AddDatePickerContentControl(NewContentControl,
            "DatePickerControl" + NewContentControl.ID);
    }
}
Private Sub ActiveDocument_DatePickerContentControlAfterAdd( _
    ByVal NewContentControl As Word.ContentControl, _
    ByVal InUndoRedo As Boolean)

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    If NewContentControl.Type = Word.WdContentControlType. _
        wdContentControlDate Then
        vstoDoc.Controls.AddDatePickerContentControl(NewContentControl, _
            "DatePickerControl" + NewContentControl.ID)
    End If
End Sub

Remarques

Utilisez cette méthode pour ajouter un nouveau DatePickerContentControl qui est basé sur un contrôle de contenu natif dans le document au moment de l’exécution. Cela est utile lorsque vous créez un au moment de DatePickerContentControl l’exécution et que vous souhaitez recréer le même contrôle la prochaine fois que le document est ouvert. Pour plus d'informations, consultez Adding Controls to Office Documents at Run Time.

S’applique à

AddDatePickerContentControl(Range, String)

Ajoute un nouveau DatePickerContentControl à la plage spécifiée dans le document.

public:
 Microsoft::Office::Tools::Word::DatePickerContentControl ^ AddDatePickerContentControl(Microsoft::Office::Interop::Word::Range ^ range, System::String ^ name);
public Microsoft.Office.Tools.Word.DatePickerContentControl AddDatePickerContentControl (Microsoft.Office.Interop.Word.Range range, string name);
abstract member AddDatePickerContentControl : Microsoft.Office.Interop.Word.Range * string -> Microsoft.Office.Tools.Word.DatePickerContentControl
Public Function AddDatePickerContentControl (range As Range, name As String) As DatePickerContentControl

Paramètres

range
Range

Range qui indique les limites du nouveau contrôle.

name
String

Nom du nouveau contrôle.

Retours

DatePickerContentControl qui a été ajouté au document.

Exceptions

name a la valeur null ou est de longueur nulle.

Un contrôle du même nom se trouve déjà dans la ControlCollection.

Exemples

L’exemple de code suivant ajoute un nouveau DatePickerContentControl au début du document. L’exemple modifie également le format dans lequel le contrôle affiche les dates.

Cette version est destinée à une personnalisation au niveau du document. Pour utiliser ce code, collez-le dans la ThisDocument classe de votre projet et appelez la AddDatePickerControlAtRange méthode à partir de la ThisDocument_Startup méthode .

private Microsoft.Office.Tools.Word.DatePickerContentControl datePickerControl2;

private void AddDatePickerControlAtRange()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();

    datePickerControl2 = this.Controls.AddDatePickerContentControl(this.Paragraphs[1].Range,
         "datePickerControl2");
    datePickerControl2.DateDisplayFormat = "MMMM d, yyyy";
    datePickerControl2.PlaceholderText = "Choose a date";
}
Dim datePickerControl2 As Microsoft.Office.Tools.Word.DatePickerContentControl

Private Sub AddDatePickerControlAtRange()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    datePickerControl2 = Me.Controls.AddDatePickerContentControl(Me.Paragraphs(1).Range, "datePickerControl2")
    datePickerControl2.DateDisplayFormat = "MMMM d, yyyy"
    datePickerControl2.PlaceholderText = "Choose a date"
End Sub

Cette version concerne un complément au niveau de l’application qui cible .NET Framework 4 ou .NET Framework 4.5. Pour utiliser ce code, collez-le dans la ThisAddIn classe de votre projet et appelez la AddDatePickerControlAtRange méthode à partir de la ThisAddIn_Startup méthode .

private Microsoft.Office.Tools.Word.DatePickerContentControl datePickerControl2;

private void AddDatePickerControlAtRange()
{
    if (this.Application.ActiveDocument == null)
        return;

    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.Paragraphs[1].Range.InsertParagraphBefore();

    datePickerControl2 = vstoDoc.Controls.AddDatePickerContentControl(
        vstoDoc.Paragraphs[1].Range,
         "datePickerControl2");
    datePickerControl2.DateDisplayFormat = "MMMM d, yyyy";
    datePickerControl2.PlaceholderText = "Choose a date";
}
Dim datePickerControl2 As Microsoft.Office.Tools.Word.DatePickerContentControl

Private Sub AddDatePickerControlAtRange()
    If Me.Application.ActiveDocument Is Nothing Then
        Return
    End If

    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    vstoDoc.Paragraphs(1).Range.InsertParagraphBefore()
    datePickerControl2 = vstoDoc.Controls.AddDatePickerContentControl( _
        vstoDoc.Paragraphs(1).Range, "datePickerControl2")
    datePickerControl2.DateDisplayFormat = "MMMM d, yyyy"
    datePickerControl2.PlaceholderText = "Choose a date"
End Sub

Remarques

Utilisez cette méthode pour ajouter un nouveau DatePickerContentControl à une plage spécifiée dans le document au moment de l’exécution. Pour plus d'informations, consultez Adding Controls to Office Documents at Run Time.

S’applique à