Share via


ControlCollection.AddDatePickerContentControl, méthode (String)

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

Espace de noms :  Microsoft.Office.Tools.Word
Assembly :  Microsoft.Office.Tools.Word (dans Microsoft.Office.Tools.Word.dll)

Syntaxe

'Déclaration
Function AddDatePickerContentControl ( _
    name As String _
) As DatePickerContentControl
DatePickerContentControl AddDatePickerContentControl(
    string name
)

Paramètres

Valeur de retour

Type : Microsoft.Office.Tools.Word.DatePickerContentControl
DatePickerContentControl ajouté au document.

Exceptions

Exception Condition
ArgumentNullException

name est nullune référence null (Nothing en Visual Basic) ou une longueur nulle.

ControlNameAlreadyExistsException

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

Notes

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 Ajout de contrôles à des documents Office au moment de l'exécution.

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 classe ThisDocument de votre projet, puis appelez la méthode AddDatePickerControlAtSelection à partir de la méthode ThisDocument_Startup.

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
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";
}

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

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
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";
}

Sécurité .NET Framework

Voir aussi

Référence

ControlCollection Interface

AddDatePickerContentControl, surcharge

Microsoft.Office.Tools.Word, espace de noms

Autres ressources

Ajout de contrôles à des documents Office au moment de l'exécution

Comment : ajouter des contrôles de contenu à des documents Word