DateTimePicker.Format DateTimePicker.Format DateTimePicker.Format DateTimePicker.Format Property

定義

取得或設定控制項中,日期和時間顯示的格式。Gets or sets the format of the date and time displayed in the control.

public:
 property System::Windows::Forms::DateTimePickerFormat Format { System::Windows::Forms::DateTimePickerFormat get(); void set(System::Windows::Forms::DateTimePickerFormat value); };
public System.Windows.Forms.DateTimePickerFormat Format { get; set; }
member this.Format : System.Windows.Forms.DateTimePickerFormat with get, set
Public Property Format As DateTimePickerFormat

屬性值

例外狀況

範例

CustomFormat 下列DateTimePicker程式碼範例會設定屬性, 使會將日期顯示為 "六月 01, 2001-星期五"。The following code example sets the CustomFormat property so that the DateTimePicker will display the date as "June 01, 2001 - Friday". 此程式碼假設已DateTimePicker Form在上建立控制項的實例。This code assumes that an instance of a DateTimePicker control has been created on a Form.

public:
   void SetMyCustomFormat()
   {
      // Set the Format type and the CustomFormat string.
      dateTimePicker1->Format = DateTimePickerFormat::Custom;
      dateTimePicker1->CustomFormat = "MMMM dd, yyyy - dddd";
   }
public void SetMyCustomFormat()
{
   // Set the Format type and the CustomFormat string.
   dateTimePicker1.Format = DateTimePickerFormat.Custom;
   dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
}

Public Sub SetMyCustomFormat()
    ' Set the Format type and the CustomFormat string.
    dateTimePicker1.Format = DateTimePickerFormat.Custom
    dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd"
End Sub 'SetMyCustomFormat

備註

此屬性會決定顯示日期的日期/時間格式。This property determines the date/time format the date is displayed in. 日期/時間格式是以使用者在其作業系統中的地區設定為基礎。The date/time format is based on the user's regional settings in their operating system.

注意

屬性的DateTimePickerFormat.Custom屬性必須設定CustomFormat為, 才會影響所顯示日期和時間的格式。 FormatThe Format property must be set to DateTimePickerFormat.Custom for the CustomFormat property to affect the formatting of the displayed date and time.

若只要顯示中DateTimePicker的時間, 請Format將設定Time為, 並ShowUpDown將屬性true設為。To display only time in a DateTimePicker, set the Format to Time, and the ShowUpDown property to true.

適用於

另請參閱