DateTimePicker Control (VBCCRDateTimePicker)
The VBCCRDateTimePicker control provides a user-friendly interface for selecting dates and times. It supports various display formats, date range restrictions, and custom calendar appearances.
Properties
DateTime Properties
Value
: Get or set the currently selected date and timeMinDate
: Minimum selectable dateMaxDate
: Maximum selectable dateYear
: Currently selected yearMonth
: Currently selected monthDay
: Currently selected dayHour
: Currently selected hourMinute
: Currently selected minuteSecond
: Currently selected second
Display Properties
Format
: Display format (short date, long date, time, etc.)CustomFormat
: Custom display format stringShowUpDown
: Whether to display up/down adjustment buttonsRightToLeft
: Whether to display right-to-leftCalendarTitleBackColor
: Calendar title background colorCalendarTrailingForeColor
: Foreground color for dates not in the current month
Behavior Properties
Enabled
: Enable/disable stateCheckBox
: Whether to display checkboxChecked
: Checkbox checked state
Methods
Date Operations
vb
' Set date time
SetValue(NewDate As Date)
' Get current value
GetValue() As Date
' Set date range
SetRange(MinDate As Date, MaxDate As Date)
' Set time portion
SetTime(Hour As Integer, Minute As Integer, Second As Integer)
Events
Change()
: Triggered when date time value changesCloseUp()
: Triggered when dropdown calendar closesDropDown()
: Triggered when dropdown calendar displaysFormat(ByVal DateString As String)
: Triggered when formatting dateKeyDown(KeyCode As Integer, Shift As Integer)
: Key press event
Code Examples
Basic Usage
vb
Private Sub InitDateTimePicker()
With DateTimePicker1
' Set date range
.MinDate = DateSerial(2000, 1, 1)
.MaxDate = DateSerial(2030, 12, 31)
' Set current date
.Value = Date
' Set display format
.Format = dtpShortDate
End With
End Sub
Custom Format
vb
Private Sub SetCustomFormat()
With DateTimePicker1
.Format = dtpCustom
' Custom format string
' yyyy: year (4 digits)
' MM: month
' dd: day
' HH: hour (24-hour format)
' mm: minute
' ss: second
.CustomFormat = "yyyy-MM-dd HH:mm:ss"
End With
End Sub
Date Range Validation
vb
Private Sub ValidateDateRange(ByVal NewDate As Date) As Boolean
With DateTimePicker1
If NewDate < .MinDate Or NewDate > .MaxDate Then