DateTimePicker Format: Short, Time, default and Custom Format : DateTimePicker « GUI Windows Form « C# / C Sharp






DateTimePicker Format: Short, Time, default and Custom Format

DateTimePicker Format: Short, Time, default and Custom Format

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
  private System.Windows.Forms.DateTimePicker dateTimePicker1;
  private System.Windows.Forms.Label label1;
  private System.Windows.Forms.Label label2;
  private System.Windows.Forms.Label label3;
  private System.Windows.Forms.Label label4;
  private System.Windows.Forms.DateTimePicker dateTimePicker2;
  private System.Windows.Forms.DateTimePicker dateTimePicker3;
  private System.Windows.Forms.DateTimePicker dateTimePicker4;

  public Form1() {
        InitializeComponent();
  }

  private void InitializeComponent()
  {
    this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
    this.label1 = new System.Windows.Forms.Label();
    this.label2 = new System.Windows.Forms.Label();
    this.label3 = new System.Windows.Forms.Label();
    this.label4 = new System.Windows.Forms.Label();
    this.dateTimePicker2 = new System.Windows.Forms.DateTimePicker();
    this.dateTimePicker3 = new System.Windows.Forms.DateTimePicker();
    this.dateTimePicker4 = new System.Windows.Forms.DateTimePicker();
    this.SuspendLayout();
    // 
    // dateTimePicker1
    // 
    this.dateTimePicker1.Location = new System.Drawing.Point(92, 15);
    this.dateTimePicker1.Name = "dateTimePicker1";
    this.dateTimePicker1.Size = new System.Drawing.Size(200, 21);
    this.dateTimePicker1.TabIndex = 0;
    // 
    // label1
    // 
    this.label1.AutoSize = true;
    this.label1.Location = new System.Drawing.Point(12, 19);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(30, 13);
    this.label1.TabIndex = 2;
    this.label1.Text = "Long:";
    // 
    // label2
    // 
    this.label2.AutoSize = true;
    this.label2.Location = new System.Drawing.Point(12, 54);
    this.label2.Name = "label2";
    this.label2.Size = new System.Drawing.Size(33, 13);
    this.label2.TabIndex = 3;
    this.label2.Text = "Short:";
    // 
    // label3
    // 
    this.label3.AutoSize = true;
    this.label3.Location = new System.Drawing.Point(12, 92);
    this.label3.Name = "label3";
    this.label3.Size = new System.Drawing.Size(29, 13);
    this.label3.TabIndex = 4;
    this.label3.Text = "Time:";
    // 
    // label4
    // 
    this.label4.AutoSize = true;
    this.label4.Location = new System.Drawing.Point(12, 128);
    this.label4.Name = "label4";
    this.label4.Size = new System.Drawing.Size(64, 13);
    this.label4.TabIndex = 5;
    this.label4.Text = "Custom ISO:";
    // 
    // dateTimePicker2
    // 
    this.dateTimePicker2.Format = System.Windows.Forms.DateTimePickerFormat.Short;
    this.dateTimePicker2.Location = new System.Drawing.Point(92, 50);
    this.dateTimePicker2.Name = "dateTimePicker2";
    this.dateTimePicker2.Size = new System.Drawing.Size(200, 21);
    this.dateTimePicker2.TabIndex = 6;
    // 
    // dateTimePicker3
    // 
    this.dateTimePicker3.Format = System.Windows.Forms.DateTimePickerFormat.Time;
    this.dateTimePicker3.Location = new System.Drawing.Point(92, 88);
    this.dateTimePicker3.Name = "dateTimePicker3";
    this.dateTimePicker3.Size = new System.Drawing.Size(200, 21);
    this.dateTimePicker3.TabIndex = 7;
    // 
    // dateTimePicker4
    // 
    this.dateTimePicker4.CustomFormat = "yyyy-mm-dd";
    this.dateTimePicker4.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
    this.dateTimePicker4.Location = new System.Drawing.Point(92, 124);
    this.dateTimePicker4.Name = "dateTimePicker4";
    this.dateTimePicker4.Size = new System.Drawing.Size(200, 21);
    this.dateTimePicker4.TabIndex = 8;
    // 
    // Form1
    // 
    this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize = new System.Drawing.Size(348, 192);
    this.Controls.Add(this.dateTimePicker4);
    this.Controls.Add(this.dateTimePicker3);
    this.Controls.Add(this.dateTimePicker2);
    this.Controls.Add(this.label4);
    this.Controls.Add(this.label3);
    this.Controls.Add(this.label2);
    this.Controls.Add(this.label1);
    this.Controls.Add(this.dateTimePicker1);
    this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    this.Name = "Form1";
    this.Text = "Date Controls";
    this.ResumeLayout(false);
    this.PerformLayout();

  }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}


           
       








Related examples in the same category

1.Set DateTimePicker Min Date and Max DateSet DateTimePicker Min Date and Max Date
2.DateTimePicker Value changed event (Selected event)DateTimePicker Value changed event (Selected event)