更新: 2008 年 7 月
表示文档中的日期选择器控件。
命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word.v9.0(在 Microsoft.Office.Tools.Word.v9.0.dll 中)
语法
声明
<DefaultBindingPropertyAttribute("Text")> _
<PermissionSetAttribute(SecurityAction.Demand, Name := "FullTrust")> _
Public NotInheritable Class DatePickerContentControl _
    Inherits ContentControlBase _
    Implements ISupportInitializeControl, ISupportInitialize
用法
Dim instance As DatePickerContentControl
[DefaultBindingPropertyAttribute("Text")]
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public sealed class DatePickerContentControl : ContentControlBase, 
    ISupportInitializeControl, ISupportInitialize
备注
DatePickerContentControl 提供一个日历,以使用户能够选择日期。在最终用户单击该控件中的下拉箭头时,该日历会出现。
若要指定显示日期的格式,请使用 DateDisplayFormat 和 DateDisplayLocale 属性。若要选择区域日历,请使用 DateCalendarType 属性。
内容控件
可用于设计 Microsoft Office Word 中的文档和模板的内容控件类型有八种,DatePickerContentControl 是其中之一。内容控件具有一个用户界面 (UI),其中包含类似于窗体的受控输入。使用内容控件可以防止用户编辑文档或模板的受保护部分,还可以将内容控件绑定到数据源。有关更多信息,请参见内容控件。
示例
下面的代码示例会在文档开头添加一个新的 DatePickerContentControl。该示例还修改控件显示日期的格式。
此版本针对的是文档级自定义项。若要使用此代码,请将其粘贴到项目内的 ThisDocument 类中,然后从 ThisDocument_Startup 方法中调用 AddDatePickerControlAtSelection 方法。
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";
}
此版本针对的是应用程序级外接程序。若要使用此代码,请将其粘贴到项目内的 ThisAddIn 类中,然后从 ThisAddIn_Startup 方法中调用 AddDatePickerControlAtSelection 方法。
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 = Me.Application.ActiveDocument.GetVstoObject()
    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 = this.Application.ActiveDocument.GetVstoObject();
    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";
}
继承层次结构
System.Object
  Microsoft.VisualStudio.Tools.Office.RemoteComponent
    Microsoft.VisualStudio.Tools.Office.RemoteBindableComponent
      Microsoft.Office.Tools.Word.ContentControlBase
        Microsoft.Office.Tools.Word.DatePickerContentControl
线程安全
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。
另请参见
参考
Microsoft.Office.Tools.Word 命名空间
其他资源
修订记录
| 日期 | 修订记录 | 原因 | 
|---|---|---|
| 2008 年 7 月 | 添加了一个针对应用程序级外接程序的代码示例版本。 | SP1 功能更改。 |