BeepDatePicker
A comprehensive date and time picker control with format masking, calendar popup, business validation, and companion time/date components
Table of Contents
Overview
Namespace: TheTechIdea.Beep.Winform.Controls
Assembly: TheTechIdea.Beep.Winform.Controls.dll
Inheritance: BeepDatePicker → BaseControl → Control
Implements: IBeepComponent (via BaseControl), IBeepUIComponent (via BaseControl)
Toolbox: Beep Controls category, display name "Beep Date Picker"
BeepDatePicker is a feature-rich date/time input control that provides a clean, headerless design where the entire control surface is rendered directly via owner-draw GDI+. There are no child TextBox or Button controls; instead, text, calendar icon, and dropdown button are all painted directly. It supports 15 predefined date format styles, custom format strings, culture-aware parsing/formatting, a calendar popup via BeepDatePickerView, business application features (min/max dates, weekends, excluded dates, auto-adjust to business days), validation with visual error feedback, keyboard navigation (F4/Alt+Down for popup), and auto-submit behavior.
The control is defined in a single source file: BeepDatePicker.cs (1082 lines). Related companion controls (BeepDatePickerView, BeepTimePicker, BeepDateDropDown, BeepDateTimePicker) live in the same Dates\ directory and provide extended calendar/time selection capabilities.
Key Features
- Owner-draw rendering: No child controls; all text, borders, and icon painted directly for maximum performance and theme integration
- 15 date format styles: ShortDate, LongDate, YearMonth, Custom, FullDateTime, ShortDateTime, DayMonthYear, ISODate, ISODateTime, TimeOnly, ShortTime, MonthDay, DayOfWeek, RFC1123, UniversalSortable
- Culture-aware: Respects the assigned
CultureInfofor both formatting and parsing - Inline keyboard editing: Type dates directly with character-level validation; press Enter to commit, Escape to cancel editing
- Calendar popup: Opens
BeepDatePickerViewinside aBeepPopupFormpositioned below the control - Popup time spinner: The calendar view includes an inline time spinner (up/down chevrons) for adjusting hours/minutes
- Date constraining: MinDate, MaxDate, ExcludedDates, Weekends
- Business context methods: Pre-built configurations for Due Date, Creation Date, Event Scheduling, Birth Date, Appointment
- Auto-adjust to business days: Skips weekends automatically when enabled
- Validation: Visual error highlighting (error backcolor, tooltip),
DateValidationFailedevent - AutoSubmit: Fires
DateSubmittedimmediately when a date is selected from the popup - Theme integration: Uses
CalendarBackColor,CalendarForeColor,CalendarBorderColor,CalendarTitleForColor,DateFont/BodyMediumtokens - Keyboard shortcuts: F4 or Alt+Down toggles popup; Escape cancels editing; F4 handled in KeyDown
- Placeholder text: Auto-generated from the format string (e.g., "DD/MM/YYYY" replaces format codes with placeholder letters)
- AutoHeight / AutoSize: Optional auto-sizing modes for height and width
- Material Design integration: Convenience property aliases (DatePickerLabel, DatePickerHelperText, DatePickerErrorText)
- Value binding: Implements
SetValue/GetValuefor data-binding; BoundProperty defaults to "SelectedDateTime" - Highlighted dates list: Custom dates can be visually highlighted in the calendar
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| SelectedDateTime | DateTime | DateTime.Now | Gets or sets selected date/time. Fires SelectedDateTimeChanged and DateChanged events on change. |
| Value | DateTime | (alias) | Alias for SelectedDateTime for compatibility with existing code. [Browsable(false)] |
| SelectedDate | string | "" | Gets or sets selected date as formatted string. Parses via culture; applies validation. |
| DateFormatStyle | DateFormatStyle | ShortDateTime | Predefined date format style from the 15-value DateFormatStyle enum. |
| DateFormat | string | "d" | Custom format string, used when DateFormatStyle = Custom. Falls back to culture short date if empty. |
| Culture | CultureInfo | CurrentCulture | Culture for date formatting and parsing. Defaults to current culture. |
| MinDate | DateTime? | null | Minimum allowed date for selection. |
| MaxDate | DateTime? | null | Maximum allowed date for selection. |
| AllowEmpty | bool | true | Whether empty/null dates are allowed. |
| ShowDropDown | bool | true | Whether to show the calendar dropdown button icon. |
| ReadOnly | bool | false | Makes the date picker read-only (display only). |
| DateContext | string | "Date Selection" | Context description for this picker (e.g., "Due Date", "Start Date"). |
| AutoAdjustToBusinessDays | bool | false | Automatically adjust selected dates to skip weekends (business days only). |
| HighlightToday | bool | true | Highlight today's date in the calendar popup. |
| Weekends | string[] | ["Saturday","Sunday"] | Days of the week considered as weekends (culture-independent). |
| ExcludedDates | List<DateTime> | empty list | Specific dates to exclude from selection. |
| HighlightedDates | List<DateTime> | empty list | Dates to highlight in the calendar popup. |
| ShowValidationIcon | bool | true | Show validation error visual (tooltip + error backcolor) when date is invalid. |
| AutoSubmit | bool | false | Automatically submit date when selected from calendar popup (fires DateSubmitted). |
| ValidationErrorMessage | string | "" | Current validation error message (read-only, private setter). |
| AutoHeight | bool | true | Automatically calculates height based on font and padding. |
| AutoSize | bool | false | Auto-sizes width to fit formatted date text. Height governed by AutoHeight. |
| DatePickerLabel | string | (base LabelText) | Material Design convenience binding to LabelText. |
| DatePickerHelperText | string | (base HelperText) | Material Design convenience binding to HelperText. |
| DatePickerErrorText | string | (base ErrorText) | Material Design convenience binding to ErrorText. |
| DatePickerHasError | bool | (base HasError) | Material Design convenience binding to HasError. |
| DatePickerAutoSizeForMaterial | bool | true | Whether material sizing compensation is applied. |
Methods
| Method | Signature | Description |
|---|---|---|
| ConfigureForDueDate | void ConfigureForDueDate() | Sets ShortDateTime, context "Due Date", MinDate=today, business days, validation on. |
| ConfigureForCreationDate | void ConfigureForCreationDate() | Sets ShortDate, context "Creation Date", MaxDate=today, read-only, no dropdown. |
| ConfigureForEventScheduling | void ConfigureForEventScheduling() | Sets FullDateTime, context "Event Date", MinDate=today, AutoSubmit. |
| ConfigureForBirthDate | void ConfigureForBirthDate() | Sets ShortDate, context "Birth Date", MaxDate=today, MinDate=120 years ago. |
| ConfigureForAppointment | void ConfigureForAppointment() | Sets ShortDateTime, context "Appointment Date", MinDate=today, MaxDate=6 months out, AutoSubmit. |
| AddBusinessHolidays | void AddBusinessHolidays(int year) | Adds New Year's Day, Christmas Day, Boxing Day to ExcludedDates for given year. |
| SetBusinessDateRange | void SetBusinessDateRange(DateTime start, DateTime end) | Sets MinDate/MaxDate; clamps current selection into range. |
| GetNextBusinessDay | DateTime GetNextBusinessDay(DateTime date) | Returns the next date that is not a weekend and not in ExcludedDates. |
| IsDateValid | bool IsDateValid(DateTime date) | Checks against MinDate, MaxDate, ExcludedDates, Weekends (if auto-adjust enabled). |
| GetCurrentFormat | string GetCurrentFormat() | Returns the resolved .NET format string based on DateFormatStyle, Culture, and DateFormat. |
| SetValue | override void SetValue(object value) | Accepts DateTime, string, or object. Parses if needed. Sets SelectedDateTime. |
| GetValue | override object GetValue() | Returns SelectedDateTime if not MinValue, otherwise null. |
| Reset | void Reset() | Resets SelectedDateTime to DateTime.Now. |
| Clear | void Clear() | Clears to DateTime.MinValue if AllowEmpty; clears validation error. |
| ApplyTheme | override void ApplyTheme() | Applies CalendarBackColor/ForeColor/BorderColor, DateFont token, icon pre-rendering in background. |
| Draw | override void Draw(Graphics g, Rectangle rect) | Container draw override for use by BeepGridPro and hosting controls. |
| DrawContent | protected override void DrawContent(Graphics g) | Called by BaseControl. Delegates to PaintCore for actual rendering. |
| GetPreferredSize | override Size GetPreferredSize(Size proposedSize) | Delegates to base. Used by layout engine. |
Events
| Event | Args | Description |
|---|---|---|
| SelectedDateTimeChanged | EventArgs | Fired whenever SelectedDateTime changes (direct assignment or popup selection). |
| DateChanged | DateChangedEventArgs | Fired with old and new DateTime values on change (OldDate, NewDate). |
| DateSubmitted | DateSubmittedEventArgs | Fired when date is auto-submitted (AutoSubmit=true) or committed via popup OK. |
| DateValidationFailed | DateValidationEventArgs | Fired when a date fails business rule validation (range, weekends, excluded). |
| CalendarOpened | EventArgs | Fired when the calendar popup opens. |
| CalendarClosed | EventArgs | Fired when the calendar popup closes. |
| CalendarOkClicked | DateTimeDialogResultEventArgs | Bubbles up the OK button click from the calendar view with the selected DateTime. |
| CalendarCancelClicked | DateTimeDialogResultEventArgs | Bubbles up the Cancel button click from the calendar view. |
Event Args Classes (defined in BeepDatePicker.cs)
| Class | Properties | Description |
|---|---|---|
| DateChangedEventArgs | DateTime OldDate, DateTime NewDate | Carries the old and new date values for change tracking. |
| DateSubmittedEventArgs | DateTime SelectedDate, string Context | Carries the submitted date and its context string. |
| DateValidationEventArgs | DateTime InvalidDate, string ErrorMessage | Carries the rejected date and the reason for rejection. |
| DateTimeDialogResultEventArgs | DateTime? SelectedDateTime, string Context, bool IsConfirmed | Carries the dialog result with confirmation flag, selected date/time, and context. |
Theming
BeepDatePicker integrates with the BeepThemesManager through the ApplyTheme() override. It reads from the following IBeepTheme tokens:
| Theme Token | Purpose | Fallback |
|---|---|---|
| CalendarBackColor | Control background color (BackColor) | None (uses base) |
| CalendarForeColor | Text color for the date display | ForeColor (base) |
| CalendarBorderColor | Border and divider color | BorderColor |
| CalendarTitleForColor | Icon tint color for the calendar SVG icon | ForeColor |
| DateFont | Primary text font (via BeepThemesManager.ToFont) | BodyMedium token |
| BodyMedium | Fallback font token when DateFont is not set | SystemFonts.DefaultFont |
| TextBoxErrorBackColor | Background when validation fails | Color.Empty |
The calendar icon SVG is pre-rendered in multiple sizes (8, 12, 14, 16, 18, 20, 24, 28, 32 px) via Task.Run for smooth scaling. The ApplyTheme method also propagates themes to child objects (calendarIcon, _calendarView) and calls InvalidateOnce() for batched repaint. The _textFont is resolved with a safe fallback chain: DateFont token → BodyMedium token → SystemFonts.DefaultFont.
Examples
Example 1: Basic Usage with Due Date Configuration
var datePicker = new BeepDatePicker
{
Location = new Point(20, 20),
Width = 250,
Theme = myTheme // Optional IBeepTheme instance
};
datePicker.ConfigureForDueDate();
this.Controls.Add(datePicker);
datePicker.DateSubmitted += (s, e) =>
{
Console.WriteLine($"Due date submitted: {e.SelectedDate} ({e.Context})");
};
Example 2: Custom Format with Validation
var datePicker = new BeepDatePicker
{
DateFormatStyle = DateFormatStyle.ISODateTime, // "yyyy-MM-dd HH:mm:ss"
MinDate = DateTime.Today.AddYears(-1),
MaxDate = DateTime.Today.AddYears(1),
AutoAdjustToBusinessDays = true,
Weekends = new[] { "Friday", "Saturday" }, // Custom weekend
ShowValidationIcon = true
};
datePicker.DateValidationFailed += (s, e) =>
{
MessageBox.Show(e.ErrorMessage, "Invalid Date",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
};
Example 3: Data-Binding and Value Integration
datePicker.SetValue(DateTime.Today.AddDays(7));
datePicker.SelectedDate = "2025-12-31";
var value = datePicker.GetValue(); // DateTime? (null if empty/cleared)
datePicker.Reset(); // Set to DateTime.Now
datePicker.Clear(); // Set to DateTime.MinValue (if AllowEmpty)
datePicker.AddBusinessHolidays(DateTime.Now.Year);
var nextBiz = datePicker.GetNextBusinessDay(DateTime.Today);
Example 4: Read-Only Display Mode
var displayPicker = new BeepDatePicker
{
SelectedDateTime = new DateTime(2025, 6, 15, 14, 30, 0),
DateFormatStyle = DateFormatStyle.ShortDateTime,
ReadOnly = true,
ShowDropDown = false,
AllowEmpty = false
};
// User cannot edit or open the calendar popup
Example 5: Material Design Integration
var materialPicker = new BeepDatePicker
{
PainterKind = BaseControlPainterKind.Material,
DatePickerLabel = "Appointment Date",
DatePickerHelperText = "Select a future date and time",
DatePickerAutoSizeForMaterial = true
};
materialPicker.DatePickerHasError = true;
materialPicker.DatePickerErrorText = "Date is in the past";
Example 6: Business Date Range and Appointment Configuration
datePicker.ConfigureForAppointment();
datePicker.SetBusinessDateRange(
DateTime.Today.AddDays(1),
DateTime.Today.AddMonths(3));
datePicker.AddBusinessHolidays(DateTime.Now.Year);
Architecture
BeepDatePicker uses a headerless, owner-draw design with no child controls. The layout is computed in PaintCore using three layout constants: ButtonWidth=24, Padding=3. The right side of the control contains the dropdown area with a dividing line and a calendar SVG icon.
When the user clicks the dropdown area or presses F4/Alt+Down, a BeepPopupForm is created hosting a BeepDatePickerView which provides a full calendar grid with navigation, time spinner, and OK/Cancel footer links. The popup closes on OK (validates date, fires events) or Cancel (fires CancelClicked only).
File breakdown (Dates directory):
| File | Responsibility |
|---|---|
| BeepDatePicker.cs (1082 lines) | Main date picker: rendering (PaintCore), keyboard input, business logic, popup management, event args classes |
| BeepDatePickerView.cs (926 lines) | Calendar popup view: month grid, day selection, time spinner, OK/Cancel footer, header with nav chevrons |
| BeepTimePicker.cs (1278 lines) | Standalone time picker with TextBox, spin buttons, dropdown, 6 time formats, business features |
| BeepDateTimePicker.cs (37 lines) | Full-featured date/time picker stub (multi-mode: Single, Range, Multiple, Appointment, etc.) |
| BeepDateTimePicker.Core.cs | Core fields, events, initialization, constructor for BeepDateTimePicker |
| BeepDateTimePicker.Properties.cs | All properties for BeepDateTimePicker |
| BeepDateTimePicker.Events.cs | Event handlers (mouse, keyboard, context menu) |
| BeepDateTimePicker.Methods.cs | Public methods (node operations, search) |
| BeepDateTimePicker.Drawing.cs | DrawContent override and painting delegation |
| BeepDateDropDown.cs (47 lines) | Inline-editing date dropdown inheriting from BeepTextBox |
| BeepDateDropDown.Core.cs | Core fields, events, initialization |
| BeepDateDropDown.Properties.cs | All properties (Mode, SelectedDateTime, constraints) |
| BeepDateDropDown.Events.cs | Event handlers |
| BeepDateDropDown.Methods.cs | Date parsing, formatting, validation |
| BeepDateDropDown.Drawing.cs | DrawContent override |
| BeepDateDropDown.SegmentEditing.cs | Segment-level editing for masked input |
| BeepDateDropDown.Sync.cs | Synchronization between text and calendar |
| Models/enums.cs | All date/time enumerations (17 enums: DatePickerMode, ReturnDateTimeType, etc.) |
| Models/DateTimePickerModels.cs | DateTimePickerEventArgs class |
| Models/DateTimePickerProperties.cs | DateTimePicker property model class |
| Models/DatePickerModeMapping.cs | Maps DatePickerMode to view mode enumerations |
| Internal/DaysGrid.cs | Internal days grid layout helper |
| ShadowPainterFactory.cs | Factory for shadow painting |
| Painters/ (20 files) | Per-mode painting strategies (Single, Range, Appointment, Compact, MonthView, YearView, etc.) |
| HitHandlers/ (20 files) | Per-mode hit test handlers for mouse/keyboard interaction |
| Helpers/ (5 files) | ComboBox helper, QuickButton helper, HitTest helper, Layout helper, Input helper |
Companion Controls
BeepDatePickerView
A modern calendar view control (BaseControl) that displays a month calendar with navigation chevrons, responsive cell sizing, time spinner (up/down chevrons), and OK/Cancel action buttons. Used internally by BeepDatePicker as the popup calendar. Features responsive layout with minimum size enforcement (320x420 default, MinSize calculated from layout constants), theme-aware color tokens (CalendarSelectedDateBackColor, CalendarSelectedDateForColor, CalendarTodayForeColor, CalendarDaysHeaderForColor, CalendarTitleForColor), and font tokens (CalendarTitleFont, DaysHeaderFont, DateFont, CalendarSelectedFont, FooterFont). Properties: SelectedDateTime (DateTime?), ShowTime (bool, default true), Context (string). Events: DateTimeSelected, Cancelled, OkClicked, CancelClicked (both with DateTimeDialogResultEventArgs).
BeepTimePicker
A standalone time picker with a borderless TextBox child for inline editing, a dropdown button (clock SVG icon) that opens a BeepPopupForm with hour/minute/AM-PM ListBoxes, and optional spin up/down BeepButton children. Supports 6 time format styles (TwelveHour, TwentyFourHour, TwelveHourWithSeconds, TwentyFourHourWithSeconds, HoursOnly, Custom), minute interval/snapping (1-60), business hours validation (BusinessStartTime 9:00, BusinessEndTime 17:00), 24-hour toggle, seconds editing toggle, and context configurations with pre-built methods: ConfigureForMeetingTime(), ConfigureForAppointment(), ConfigureForShiftTime(), ConfigureForDeadline(). Events: SelectedTimeChanged, TimeChanged (TimeChangedEventArgs), TimeSubmitted (TimeSubmittedEventArgs), TimeValidationFailed (TimeValidationEventArgs), TimePickerOpened, TimePickerClosed.
BeepDateDropDown
An inline-editing date dropdown inheriting from BeepTextBox for full text editing capabilities (input masking, AutoComplete, Undo/Redo, selection/caret management). Supports single dates, date ranges ("MM/dd/yyyy - MM/dd/yyyy"), and date-time ranges with proper formatting. The dropdown calendar is a BeepDateTimePicker shown in a popup. 7 partial files: Core, Properties, Events, Methods, Drawing, SegmentEditing, Sync. Features: inline masking, F4 dropdown shortcut, culture-specific formatting, min/max date constraints, theme integration, validation feedback.
BeepDateTimePicker
A full-featured date/time picker control supporting 18 functional modes (Single, SingleWithTime, Range, RangeWithTime, Multiple, Appointment, Timeline, Quarterly, Compact, ModernCard, DualCalendar, WeekView, MonthView, YearView, SidebarEvent, FlexibleRange, FilteredRange, Header). Uses a pluggable painter/hit-handler architecture with 20 painter strategies per mode and 20 hit handler strategies per mode. Incomplete implementation (stub state with 8 partial files).
Enumerations
DateFormatStyle (from Beep.Vis.Modules2.0)
| Value | Format String | Example Output |
|---|---|---|
| ShortDate | Culture ShortDatePattern | "6/15/2025" |
| LongDate | Culture LongDatePattern | "Sunday, June 15, 2025" |
| YearMonth | "MMMM yyyy" | "June 2025" |
| Custom | DateFormat property | User-defined |
| FullDateTime | LongDatePattern + LongTimePattern | "Sunday, June 15, 2025 2:30:00 PM" |
| ShortDateTime | ShortDatePattern + " HH:mm" | "6/15/2025 14:30" |
| DayMonthYear | "dd MMMM yyyy" | "15 June 2025" |
| ISODate | "yyyy-MM-dd" | "2025-06-15" |
| ISODateTime | "yyyy-MM-dd HH:mm:ss" | "2025-06-15 14:30:00" |
| TimeOnly | "HH:mm:ss" | "14:30:00" |
| ShortTime | "HH:mm" | "14:30" |
| MonthDay | "MMMM dd" | "June 15" |
| DayOfWeek | "dddd" | "Sunday" |
| RFC1123 | "ddd, dd MMM yyyy HH:mm:ss 'GMT'" | "Sun, 15 Jun 2025 14:30:00 GMT" |
| UniversalSortable | "yyyy-MM-dd HH:mm:ss'Z'" | "2025-06-15 14:30:00Z" |
TimeFormatStyle (from BeepTimePicker.cs)
| Value | Format | Example |
|---|---|---|
| TwelveHour | "h:mm tt" | "2:30 PM" |
| TwentyFourHour | "HH:mm" | "14:30" |
| TwelveHourWithSeconds | "h:mm:ss tt" | "2:30:45 PM" |
| TwentyFourHourWithSeconds | "HH:mm:ss" | "14:30:45" |
| HoursOnly | "HH" or "h tt" | "14" or "2 PM" |
| Custom | TimeFormat property | User-defined |
DatePickerMode (from Models/enums.cs)
Defines functional mode for BeepDateTimePicker/BeepDateDropDown. 18 values: Single, SingleWithTime, Range, RangeWithTime, Multiple, Appointment, Timeline, Quarterly, Compact, ModernCard, DualCalendar, WeekView, MonthView, YearView, SidebarEvent, FlexibleRange, FilteredRange, Header.
ReturnDateTimeType (from Models/enums.cs)
Defines return value type: Date, DateTime, DateRange, DateTimeRange, MultipleDates, TimeOnly.
Additional Date Enums (from Models/enums.cs)
DateDropDownStyle: Default, Modern, Classic, Custom — DatePickerFormat: Long, Short, Time, Custom, ShortDate — DatePickerView: Days, Months, Years — DatePickerSelectionMode: Single, Multiple, Range — DatePickerCalendarType: Gregorian, Julian, Hebrew, Hijri, ThaiBuddhist, UmAlQura — DatePickerFirstDayOfWeek: Sunday through Saturday — DatePickerWeekNumbers: None, FirstDay, FirstFullWeek, FirstFourDayWeek, Left — DatePickerMonthDisplay: Full, Abbreviated, Numeric — DatePickerYearDisplay: Full, Abbreviated, TwoDigit — DatePickerHighlightCurrentDate: None, Background, Border, Both — DatePickerHighlightSelectedDate: None, Background, Border, Both — DatePickerDisabledDateStyle: GrayedOut, Hidden, Custom — DatePickerAnimationType: None, Fade, Slide, Zoom — DateTimePickerHitArea: 40+ hit areas covering all interactive zones (Header, DayCell, QuickButton, TimeSpinner, etc.).