Compartir a través de


ControlCollection.AddDatePickerContentControl (Método) (String)

Agrega un nuevo control DatePickerContentControl a la selección actual del documento.

Espacio de nombres:  Microsoft.Office.Tools.Word
Ensamblado:  Microsoft.Office.Tools.Word (en Microsoft.Office.Tools.Word.dll)

Sintaxis

'Declaración
Function AddDatePickerContentControl ( _
    name As String _
) As DatePickerContentControl
DatePickerContentControl AddDatePickerContentControl(
    string name
)

Parámetros

Valor devuelto

Tipo: Microsoft.Office.Tools.Word.DatePickerContentControl
El control DatePickerContentControl que se agregó al documento.

Excepciones

Excepción Condición
ArgumentNullException

name es nullreferencia null (Nothing en Visual Basic) o tiene longitud cero.

ControlNameAlreadyExistsException

Ya existe un control con el mismo nombre en ControlCollection.

Comentarios

Utilice este método para agregar un nuevo control DatePickerContentControl en la selección actual del documento en tiempo de ejecución.Para obtener más información, vea Agregar controles a documentos de Office en tiempo de ejecución.

Ejemplos

En el ejemplo de código siguiente se agrega un nuevo DatePickerContentControl al principio del documento.En el ejemplo se modifica también el formato en que el control muestra las fechas.

Se trata de una versión para una personalización en el nivel del documento.Para usar este código, péguelo en la clase ThisDocument del proyecto y llame al método AddDatePickerControlAtSelection desde el método 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";
}

Esta versión es para un complemento de nivel de aplicación que tiene como destino .NET Framework 4 o .NET Framework 4.5.Para usar este código, péguelo en la clase ThisAddIn del proyecto y llame al método AddDatePickerControlAtSelection desde el método 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";
}

Seguridad de .NET Framework

Vea también

Referencia

ControlCollection Interfaz

AddDatePickerContentControl (Sobrecarga)

Microsoft.Office.Tools.Word (Espacio de nombres)

Otros recursos

Agregar controles a documentos de Office en tiempo de ejecución

Cómo: Agregar controles de contenido a documentos de Word