Compartir a través de


ControlCollection.AddDatePickerContentControl Método

Definición

Sobrecargas

AddDatePickerContentControl(String)

Agrega un nuevo objeto DatePickerContentControl en la selección actual del documento.

AddDatePickerContentControl(ContentControl, String)

Agrega un nuevo objeto DatePickerContentControl a la colección. El nuevo control se basa en un control de contenido nativo que ya se encuentra en el documento.

AddDatePickerContentControl(Range, String)

Agrega un nuevo objeto DatePickerContentControl en el intervalo especificado en el documento.

AddDatePickerContentControl(String)

Agrega un nuevo objeto DatePickerContentControl en la selección actual del documento.

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

Parámetros

name
String

El nombre del nuevo control.

Devoluciones

El objeto DatePickerContentControl que se agregó al documento.

Excepciones

name es null o tiene una longitud cero.

Un control con el mismo nombre ya se encuentra en el objeto ControlCollection.

Ejemplos

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

Esta versión es para una personalización de nivel de documento. Para usar este código, péguelo en la ThisDocument clase del proyecto y llame al AddDatePickerControlAtSelection método desde el ThisDocument_Startup método .

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

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 ThisAddIn clase del proyecto y llame al AddDatePickerControlAtSelection método desde el ThisAddIn_Startup método .

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

Comentarios

Use este método para agregar un nuevo DatePickerContentControl en la selección actual del documento en tiempo de ejecución. Para obtener más información, consulta Adding Controls to Office Documents at Run Time.

Se aplica a

AddDatePickerContentControl(ContentControl, String)

Agrega un nuevo objeto DatePickerContentControl a la colección. El nuevo control se basa en un control de contenido nativo que ya se encuentra en el documento.

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

Parámetros

contentControl
ContentControl

El objeto ContentControl que es la base del nuevo control.

name
String

El nombre del nuevo control.

Devoluciones

El objeto DatePickerContentControl que se agregó al documento.

Excepciones

contentControles .-o- name es nullnullo tiene una longitud cero.

Un control con el mismo nombre ya se encuentra en el objeto ControlCollection.

contentControlno es una galería de bloques de creación (es decir, la Type propiedad de contentControl no tiene el valor Microsoft.Office.Interop.Word. WdContentControlType.wdContentControlDate).

Ejemplos

En el ejemplo de código siguiente se crea un nuevo DatePickerContentControl para cada control de fecha nativo que se encuentra en el documento.

Esta versión es para una personalización de nivel de documento. Para usar este código, péguelo en la ThisDocument clase del proyecto y llame al CreateDatePickerControlsFromNativeControls método desde el ThisDocument_Startup método .

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

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 ThisAddIn clase del proyecto y llame al CreateDatePickerControlsFromNativeControls método desde el ThisAddIn_Startup método .

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

En el ejemplo de código siguiente se crea un nuevo DatePickerContentControl para cada control de fecha nativo que el usuario agrega al documento.

Esta versión es para una personalización de nivel de documento. Para usar este código, péguelo en la ThisDocument clase del proyecto. Para C#, también debe adjuntar el ThisDocument_DatePickerContentControlAfterAdd controlador de eventos al ContentControlAfterAdd evento de la ThisDocument clase .

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

Para usar este código, péguelo en la ThisAddIn clase del proyecto. Además, debe adjuntar el ActiveDocument_DatePickerContentControlAfterAdd controlador de eventos al ContentControlAfterAdd evento del documento activo.

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

Comentarios

Use este método para agregar un nuevo DatePickerContentControl basado en un control de contenido nativo en el documento en tiempo de ejecución. Esto resulta útil cuando se crea en DatePickerContentControl tiempo de ejecución y desea volver a crear el mismo control la próxima vez que se abra el documento. Para obtener más información, consulta Adding Controls to Office Documents at Run Time.

Se aplica a

AddDatePickerContentControl(Range, String)

Agrega un nuevo objeto DatePickerContentControl en el intervalo especificado en el documento.

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

Parámetros

range
Range

Un objeto Range que proporciona los límites del nuevo control.

name
String

El nombre del nuevo control.

Devoluciones

El objeto DatePickerContentControl que se agregó al documento.

Excepciones

name es null o tiene una longitud cero.

Un control con el mismo nombre ya se encuentra en el objeto ControlCollection.

Ejemplos

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

Esta versión es para una personalización de nivel de documento. Para usar este código, péguelo en la ThisDocument clase del proyecto y llame al AddDatePickerControlAtRange método desde el ThisDocument_Startup método .

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

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 ThisAddIn clase del proyecto y llame al AddDatePickerControlAtRange método desde el ThisAddIn_Startup método .

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

Comentarios

Use este método para agregar un nuevo DatePickerContentControl en un intervalo especificado en el documento en tiempo de ejecución. Para obtener más información, consulta Adding Controls to Office Documents at Run Time.

Se aplica a