Compartir a través de


ControlCollection.AddDatePickerContentControl (Método) (Range, String)

Agrega un nuevo control DatePickerContentControl en el intervalo especificado 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 ( _
    range As Range, _
    name As String _
) As DatePickerContentControl
DatePickerContentControl AddDatePickerContentControl(
    Range range,
    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 un intervalo especificado 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 AddDatePickerControlAtRange desde el método ThisDocument_Startup.

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

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 AddDatePickerControlAtRange desde el método ThisAddIn_Startup.

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

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