Imports System.ComponentModel Public Class Form1 Private WithEvents Label1 As Label Private WithEvents Dtp1, Dtp2 As DateTimePicker Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Label1 = New Label() With {.Location = New Point(8, 8), .Text = "Label1", .AutoSize = True} Dtp1 = New DateTimePicker() With {.Location = New Point(8, 50)} Dtp2 = New DateTimePicker() With {.Location = New Point(8, 90)} Dtp1.Format = DateTimePickerFormat.Custom Dtp1.CustomFormat = "yyyy/MM/dd HH:mm:ss" Dtp2.Format = DateTimePickerFormat.Custom Dtp2.CustomFormat = "yyyy/MM/dd HH:mm:ss" Me.Controls.AddRange(New Control() {Label1, Dtp1, Dtp2}) Dtp1.Value = New DateTime(2017, 8, 1) Dtp2.Value = New DateTime(2017, 8, 31, 23, 59, 59) End Sub Private Sub Dtp_ValueChanged(sender As Object, e As EventArgs) Handles Dtp1.ValueChanged, Dtp2.ValueChanged Label1.Text = Dtp1.Value.ToString("yyyy/MM/dd HH:mm:ss.fffffff") & "から" & vbNewLine _ & Dtp2.Value.ToString("yyyy/MM/dd HH:mm:ss.fffffff") & "まで" End Sub #Region "自・至を逆に入力させたくない場合" 'Private Sub Dtp1_ValueChanged(sender As Object, e As EventArgs) Handles Dtp1.ValueChanged ' Dtp2.MinDate = Dtp1.Value 'End Sub 'Private Sub Dtp2_ValueChanged(sender As Object, e As EventArgs) Handles Dtp2.ValueChanged ' Dtp1.MaxDate = Dtp2.Value 'End Sub #End Region #Region "自・至を逆に入力させても良いが、入力完了後に入れ替えさせる場合" Private Sub Dtp_Validating(sender As Object, e As CancelEventArgs) Handles Dtp1.Validating, Dtp2.Validating If Dtp1.Value > Dtp2.Value Then Dim swap = Dtp1.Value Dtp1.Value = Dtp2.Value Dtp2.Value = swap End If End Sub #End Region End Class