Share via


DatePickerContentControl.DateDisplayFormat Property

Gets or sets a string that specifies the format in which the DatePickerContentControl displays dates.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
Property DateDisplayFormat As String
string DateDisplayFormat { get; set; }

Property Value

Type: System.String
A string that specifies the format in which the DatePickerContentControl displays dates.

Remarks

The default date format is the format setting specified in Microsoft Office Word, which usually depends on the locale setting of the operating system. For example, the default format of dates for the locale English (United States) is M/dd/yyyy.

Examples

The following code example adds a new DatePickerContentControl to the beginning of the document. The example uses the DateDisplayFormat property to display dates in the format MMMM d, yyyy.

This version is for a document-level customization. To use this code, paste it into the ThisDocument class in your project, and call the AddDatePickerControlAtSelection method from the ThisDocument_Startup method.

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

This version is for an application-level add-in. To use this code, paste it into the ThisAddIn class in your project, and call the AddDatePickerControlAtSelection method from the ThisAddIn_Startup method.

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

.NET Framework Security

See Also

Reference

DatePickerContentControl Interface

Microsoft.Office.Tools.Word Namespace