Share via


DateTimePicker.DropDownAlign 属性

获取或设置 DateTimePicker 控件上下拉日历的对齐方式。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
<LocalizableAttribute(True)> _
Public Property DropDownAlign As LeftRightAlignment
用法
Dim instance As DateTimePicker
Dim value As LeftRightAlignment

value = instance.DropDownAlign

instance.DropDownAlign = value
[LocalizableAttribute(true)] 
public LeftRightAlignment DropDownAlign { get; set; }
[LocalizableAttribute(true)] 
public:
property LeftRightAlignment DropDownAlign {
    LeftRightAlignment get ();
    void set (LeftRightAlignment value);
}
/** @property */
public LeftRightAlignment get_DropDownAlign ()

/** @property */
public void set_DropDownAlign (LeftRightAlignment value)
public function get DropDownAlign () : LeftRightAlignment

public function set DropDownAlign (value : LeftRightAlignment)

属性值

下拉日历在控件上的对齐方式。默认为 Left

异常

异常类型 条件

InvalidEnumArgumentException

分配的值不是 LeftRightAlignment 值之一。

备注

下拉日历可与控件的左侧或右侧对齐。

示例

下面的代码示例演示如何通过设置 DropDownAlignValueFormatCustomFormat 属性来初始化 DateTimePicker。若要运行此示例,请将下面的代码粘贴到一个窗体中,并从该窗体的构造函数或 Load 事件处理方法中调用 InitializeDateTimePicker

' Declare the DateTimePicker.
Friend WithEvents DateTimePicker1 As System.Windows.Forms.DateTimePicker


Private Sub InitializeDateTimePicker()

    ' Construct the DateTimePicker.
    Me.DateTimePicker1 = New System.Windows.Forms.DateTimePicker

    'Set size and location.
    Me.DateTimePicker1.Location = New System.Drawing.Point(40, 88)
    Me.DateTimePicker1.Size = New Size(160, 21)
    
    ' Set the alignment of the drop-down MonthCalendar to right.
    Me.DateTimePicker1.DropDownAlign = LeftRightAlignment.Right

    ' Set the Value property to 50 years before today.
    DateTimePicker1.Value = (DateTime.Now.AddYears(-50))

    'Set a custom format containing the string "of the year"
    DateTimePicker1.Format = DateTimePickerFormat.Custom
    DateTimePicker1.CustomFormat = "MMM dd, 'of the year' yyyy "

    ' Add the DateTimePicker to the form.
    Me.Controls.Add(Me.DateTimePicker1)
End Sub
// Declare the DateTimePicker.
internal System.Windows.Forms.DateTimePicker DateTimePicker1;


private void InitializeDateTimePicker()
{
    // Construct the DateTimePicker.
    this.DateTimePicker1 = new System.Windows.Forms.DateTimePicker();

    //Set size and location.
    this.DateTimePicker1.Location = new System.Drawing.Point(40, 88);
    this.DateTimePicker1.Size = new System.Drawing.Size(160, 21);
    
    // Set the alignment of the drop-down MonthCalendar to right.
    this.DateTimePicker1.DropDownAlign = LeftRightAlignment.Right;

    // Set the Value property to 50 years before today.
    DateTimePicker1.Value = System.DateTime.Now.AddYears(-50);

    //Set a custom format containing the string "of the year"
    DateTimePicker1.Format = DateTimePickerFormat.Custom;
    DateTimePicker1.CustomFormat = "MMM dd, 'of the year' yyyy ";

    // Add the DateTimePicker to the form.
    this.Controls.Add(this.DateTimePicker1);
}
internal:
   // Declare the DateTimePicker.
   System::Windows::Forms::DateTimePicker^ DateTimePicker1;

private:
   void InitializeDateTimePicker()
   {
      // Construct the DateTimePicker.
      this->DateTimePicker1 = gcnew System::Windows::Forms::DateTimePicker;
      
      //Set size and location.
      this->DateTimePicker1->Location = System::Drawing::Point( 40, 88 );
      this->DateTimePicker1->Size = System::Drawing::Size( 160, 21 );
      
      // Set the alignment of the drop-down MonthCalendar to right.
      this->DateTimePicker1->DropDownAlign = LeftRightAlignment::Right;
      
      // Set the Value property to 50 years before today.
      DateTimePicker1->Value = System::DateTime::Now.AddYears(  -50 );
      
      //Set a custom format containing the string "of the year"
      DateTimePicker1->Format = DateTimePickerFormat::Custom;
      DateTimePicker1->CustomFormat = "MMM dd, 'of the year' yyyy ";
      
      // Add the DateTimePicker to the form.
      this->Controls->Add( this->DateTimePicker1 );
   }
// Declare the DateTimePicker.
private System.Windows.Forms.DateTimePicker dateTimePicker1;

private void InitializeDateTimePicker()
{
    // Construct the DateTimePicker.
    this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
    //Set size and location.
    this.dateTimePicker1.set_Location(new System.Drawing.Point(40, 88));
    this.dateTimePicker1.set_Size(new System.Drawing.Size(160, 21));
    // Set the alignment of the drop-down MonthCalendar to right.
    this.dateTimePicker1.set_DropDownAlign(LeftRightAlignment.Right);
    // Set the Value property to 50 years before today.
    dateTimePicker1.set_Value(System.DateTime.get_Now().AddYears(-50));
    //Set a custom format containing the string "of the year"
    dateTimePicker1.set_Format(DateTimePickerFormat.Custom);
    dateTimePicker1.set_CustomFormat("MMM dd, 'of the year' yyyy ");
    // Add the DateTimePicker to the form.
    this.get_Controls().Add(this.dateTimePicker1);
} //InitializeDateTimePicker

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

DateTimePicker 类
DateTimePicker 成员
System.Windows.Forms 命名空间
LeftRightAlignment