HypernovaDesktop Components · docs
Binarymission
WinForms › Date Picker › BinaryDatePicker

BinaryDatePicker

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.DateTimeControls

A date field with a drop-down month calendar, in the manner of Outlook's date pickers: the user types a date, picks one from the calendar, or steps it with the keyboard – for order dates, due dates, dates of birth.

public partial class BinaryDatePicker : Control

Inherits from / implements: Control

Remarks

What it is for

The control is a text box and a drop-down button. The text is free text written in Format (the long date by default) or CustomFormat, and is read back as the user types. It also understands today, yesterday, tomorrow, one week from now and one week before now, and names of your own from an XML file (CustomDateXMLFeed).

Keyboard and menu

In the text: Enter commits what was typed, Up and Down move the date a month, Page Up and Page Down a year, Ctrl+A and Ctrl+S a day forward and back, and Ctrl+L (with the menu on) opens the calendar. In the calendar: the arrows move a day or a week, Page Up and Page Down a month, Home and End to the ends of the month, Enter chooses and Escape closes. The right-click menu (ShowCustomMenu) adds clipboard commands and quick dates.

The value

Value is an object: a DateTime, or – with no date (ValueIsNull) – NullDateString, or DBNull when the control is data bound. MinValue and MaxValue limit it. BinaryDateChanged reports each change.

Appearance

The text box's border is set by EditControlStyleIsExtended, BorderColor and DrawBorderAs; the button by UseDropDownImageStyle; the calendar by the Calendar..., Selection... and Today... colours, SpecialDates and Font, from which it is sized.

Examples

using System;
using System.Drawing;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.DateTimeControls;

var dueDate = new BinaryDatePicker
{
    Location = new Point(16, 16),
    Width = 220,
    Format = BinaryDatePickerFormat.Custom,
    CustomFormat = "ddd dd MMM yyyy",
    MinValue = DateTime.Today,
    NullDateString = "No due date",
    SpecialDates = new[] { new DateTime(2026, 12, 25), new DateTime(2026, 12, 26) }
};

dueDate.Value = DateTime.Today.AddDays(30);
dueDate.BinaryDateChanged += (sender, e) =>
    invoice.DueDate = dueDate.ValueIsNull ? (DateTime?)null : (DateTime)dueDate.Value;

invoiceForm.Controls.Add(dueDate);

Members at a glance

Constructors
BinaryDatePickerInitialises a date picker showing today's date in the long date format, with the right-click menu and an always-visible border.
Properties
BackColorGets or sets the background of the text box.
BinaryCultureInfoGets or sets the culture the date is written, read and shown in – month and day names, the long and short date formats.
BorderColorGets or sets the colour of the text box's border.
CalendarForeColorGets or sets the colour of the day numbers, the day names and the legend text in the calendar.
CalendarInactiveDateForeColorGets or sets the colour of the days of the previous and next months that fill the calendar's first and last rows.
CalendarLegendDisplayGets or sets whether the calendar shows a legend under the days, explaining the Today and Selection circles.
CalendarMonthAndYearTrackerColorGets or sets the colour of the two small arrows at the ends of the calendar's title, which move to the previous and next month.
CalendarMonthBackColorGets or sets the background of the calendar.
CalendarMonthTitleForeColorGets or sets the colour of the month and year in the calendar's title.
CalenderDropDownArrowGlassRenderingColorGets or sets the colour of the arrow on the glass drop-down button.
CalenderDropDownGlassRenderingEndColorGets or sets the dark colour of the glass drop-down button, also used for its outline.
CalenderDropDownGlassRenderingStartColorGets or sets the light colour of the glass drop-down button.
CloseButtonBackColorGets or sets the background colour of the calendar's Close button.
CloseButtonFlatStyleGets or sets how the calendar's Close button is drawn: flat, popup, standard or by the system.
CloseButtonForeColorGets or sets the colour of the text on the calendar's Close button.
CloseButtonTextGets or sets the caption of the calendar's Close button, which closes the calendar without changing the date.
CustomDateXMLFeedGets or sets the path of an XML file of named dates the user can type, and of dates to pick out in the calendar.
CustomDropDownImageGets or sets the picture drawn on the drop-down button when UseDropDownImageStyle is DropDownImageStyle.CustomImage.
CustomFormatGets or sets the .NET date format the text is written and read in, such as "dd/MM/yyyy" or "ddd d MMM yyyy".
DisplayTextStateGets or sets whether the user can type in the text box; the calendar works either way.
DotBorderDepthGets or sets the length of each dash in the text box's dotted border.
DotBorderGapGets or sets the space between the dashes of the text box's dotted border.
DrawBorderAsGets or sets whether the text box's border is a continuous line or dotted.
DropWindowIsShowingGets or sets whether a hosted picker's calendar is open.
EditControlStyleIsExtendedGets or sets whether the text box has the control's flat, single-line border rather than the standard sunken one.
EnableCustomDateXMLFeedGets or sets whether typed text is looked up among the named dates in CustomDateXMLFeed.
FontGets or sets the font of the date text and of the calendar, which is sized to fit it.
ForeColorGets or sets the colour of the date text.
FormatGets or sets the format the date is written in: the long or short date of the culture, or CustomFormat.
HostedFromChildContainerGets or sets whether the picker is hosted inside another control, such as a grid cell, rather than placed on a form.
IsReadOnlyGets or sets whether the date is shown but cannot be changed – neither typed nor picked from the calendar.
MarkSelectedDateGets or sets whether the calendar marks the chosen day and today with filled circles.
MaxDateTimeGets the latest date MaxValue can be set to: 31 December 9999.
MaxValueGets or sets the latest date the control accepts.
MinDateTimeGets the earliest date MinValue can be set to: 1 February 0001.
MinValueGets or sets the earliest date the control accepts.
NullDateStringGets or sets the text shown when the control holds no date, such as "No date" or "Not shipped".
RenderDropDownButtonWithVisualStylesGets or sets whether the drop-down arrow button is drawn in the Windows visual style, with a hover effect, rather than as a classic combo-box button.
SelectionDateEllipseColorGets or sets the colour of the filled circle marking the chosen day in the calendar.
SelectionDateForeColorGets or sets the colour of the chosen day's number in the calendar, drawn on its circle.
ShowBorderAlwaysGets or sets whether the text box's border is always drawn in BorderColor, rather than only while the pointer is over it or it has the focus.
ShowCustomMenuGets or sets whether right-clicking the text box shows the control's own menu.
ShowDropDownCalendarWindowAfterAdjustingForVirtualAvaliableScreenSpaceGets or sets whether the calendar opens above the control when there is no room for it below.
ShowPopupOnEnterGets or sets whether the calendar opens as soon as the control receives the focus.
SpecialDatesGets or sets dates to pick out in the calendar – holidays, delivery days, booked dates.
SpecialDatesFillColorGets or sets the background of the SpecialDates in the calendar.
SpecialDatesForeColorGets or sets the colour of the day numbers of the SpecialDates in the calendar.
TodayButtonBackColorGets or sets the background colour of the calendar's Today button.
TodayButtonFlatStyleGets or sets how the calendar's Today button is drawn: flat, popup, standard or by the system.
TodayButtonForeColorGets or sets the colour of the text on the calendar's Today button.
TodayButtonTextGets or sets the caption of the calendar's Today button, which picks today's date and closes the calendar.
TodayCloseButtonsAreVisibleGets or sets whether the calendar shows its Today and Close buttons.
TodayEllipseColorGets or sets the colour of the filled circle marking today in the calendar.
TodayForeColorGets or sets the colour of today's day number in the calendar, drawn on its circle.
UseDropDownImageStyleGets or sets what is drawn on the drop-down button: an arrow, a calendar picture, your own picture, or a glass button.
ValueGets or sets the date in the control.
ValueIsNullGets or sets whether the control holds no date, showing NullDateString.
Methods
DisposeCloses and releases the drop-down window of a hosted calendar, then the control.
OnEnterRaises the Control.Enter event, then opens the calendar when ShowPopupOnEnter is set.
OnFontChangedRaises the Control.FontChanged event and passes the new font to the calendar.
OnLeaveCommits the typed text as the date when the focus leaves the control, then raises the Control.Leave event.
OnMouseDownReads the typed text and, when the press is on the drop-down button, opens the calendar; then raises the Control.MouseDown event.
OnMouseLeaveRaises the Control.MouseLeave event and returns the drop-down button to its resting look.
OnMouseMoveRaises the Control.MouseMove event and lights up the drop-down button while the pointer is over it.
OnMouseUpReturns the drop-down button to its resting look, then raises the Control.MouseUp event.
OnPaintDraws the drop-down button in the UseDropDownImageStyle; the text box draws itself.
OnResizeFits the text box and the drop-down button to the new width, keeps the control as tall as its text, then raises the Control.Resize event.
OnSystemColorsChangedRaises the Control.SystemColorsChanged event and redraws the control in the new colours.
SelectControlTextSelects all the text in the control's text box, so the user's next keystroke replaces it.
Events
BinaryCalendarAboutToBeActivatedOccurs just before the calendar opens.
BinaryCalendarActivatedOccurs when the calendar has opened.
BinaryCalendarDeactivatedOccurs when the calendar closes – a day chosen, Today or Close pressed, Escape, or a click elsewhere.
BinaryDateAboutToBeChangedOccurs as the date is about to change: on each change of the text, when Value is set, and when the null state is set or cleared.
BinaryDateChangedOccurs whenever the date changes: picked in the calendar, set from code or the menu, stepped by a key, made null – and on each keystroke while the user types.
CustomFormatDateChangedOccurs when the user leaves the control with text that does not match CustomFormat, so you can interpret it.
MouseIsOverADateOccurs as the pointer moves over a day in the calendar, so you can show a tooltip for that date.
UserDateCustomValidatingOccurs before the typed text is read as a date – when the user presses Enter, leaves the control, clicks it or opens the calendar – so you can correct or translate it.

Constructors

BinaryDatePicker

public BinaryDatePicker()

Initialises a date picker showing today's date in the long date format, with the right-click menu and an always-visible border.

Properties

BackColor

public override Color BackColor

Gets or sets the background of the text box.

Value
The default is SystemColors.Window.
Remarks

The calendar has its own background; see CalendarMonthBackColor.

BinaryCultureInfo

public CultureInfo BinaryCultureInfo

Gets or sets the culture the date is written, read and shown in – month and day names, the long and short date formats.

Value
The default is the thread's CultureInfo.CurrentCulture. null also means the current culture.
Remarks

Set it to show dates in a culture other than the user's – new CultureInfo("fr-FR") for a French form on an English system. The calendar and the dates in CustomDateXMLFeed follow it too.

BorderColor

public Color BorderColor

Gets or sets the colour of the text box's border.

Value
The default is SystemColors.Highlight.
Remarks

A value set while EditControlStyleIsExtended is false is ignored.

CalendarForeColor

public Color CalendarForeColor

Gets or sets the colour of the day numbers, the day names and the legend text in the calendar.

Value
The default is SystemColors.ControlText.

CalendarInactiveDateForeColor

public Color CalendarInactiveDateForeColor

Gets or sets the colour of the days of the previous and next months that fill the calendar's first and last rows.

Value
The default is SystemColors.ControlDark.

CalendarLegendDisplay

public bool CalendarLegendDisplay

Gets or sets whether the calendar shows a legend under the days, explaining the Today and Selection circles.

Value
true to show it. The default is true.
Remarks

The legend is drawn only while MarkSelectedDate is also set; without it the calendar is shorter.

CalendarMonthAndYearTrackerColor

public Color CalendarMonthAndYearTrackerColor

Gets or sets the colour of the two small arrows at the ends of the calendar's title, which move to the previous and next month.

Value
The default is dark red, Color.FromArgb(128, 0, 0).
Remarks

Holding an arrow down keeps moving. Clicking the title itself opens a list of months.

CalendarMonthBackColor

public Color CalendarMonthBackColor

Gets or sets the background of the calendar.

Value
The default is SystemColors.Window.

CalendarMonthTitleForeColor

public Color CalendarMonthTitleForeColor

Gets or sets the colour of the month and year in the calendar's title.

Value
The default is dark red, Color.FromArgb(128, 0, 0).

CalenderDropDownArrowGlassRenderingColor

public Color CalenderDropDownArrowGlassRenderingColor

Gets or sets the colour of the arrow on the glass drop-down button.

Value
The default is SystemColors.ControlDarkDark.

CalenderDropDownGlassRenderingEndColor

public Color CalenderDropDownGlassRenderingEndColor

Gets or sets the dark colour of the glass drop-down button, also used for its outline.

Value
The default is SystemColors.ControlDark.

CalenderDropDownGlassRenderingStartColor

public Color CalenderDropDownGlassRenderingStartColor

Gets or sets the light colour of the glass drop-down button.

Value
The default is SystemColors.Window.
Remarks

CloseButtonBackColor

public Color CloseButtonBackColor

Gets or sets the background colour of the calendar's Close button.

Value
The default is Control.DefaultBackColor, the standard button colour.
Remarks

Takes effect the next time the calendar opens.

CloseButtonFlatStyle

public FlatStyle CloseButtonFlatStyle

Gets or sets how the calendar's Close button is drawn: flat, popup, standard or by the system.

Value
The default is FlatStyle.Standard.
Remarks

Use FlatStyle.Flat or FlatStyle.Popup for the button colours to show in full.

CloseButtonForeColor

public Color CloseButtonForeColor

Gets or sets the colour of the text on the calendar's Close button.

Value
The default is Control.DefaultForeColor, the standard button text colour.

CloseButtonText

public string CloseButtonText

Gets or sets the caption of the calendar's Close button, which closes the calendar without changing the date.

Value
The default is "Close".
Remarks

The button is 47 by 20 logical pixels, so keep a translation short.

CustomDateXMLFeed

public string CustomDateXMLFeed

Gets or sets the path of an XML file of named dates the user can type, and of dates to pick out in the calendar.

Value
A file path. The default is an empty string: no file.
Remarks

Each DateLookup gives a name the user can type – matched exactly, case included – and its date; names are used only while EnableCustomDateXMLFeed is set. Each Date under HighlightDates becomes one of the SpecialDates as soon as the path is set. Dates are read in BinaryCultureInfo.

Example
<?xml version="1.0" encoding="utf-8" ?>
<CustomDates>
  <DateLookup>
    <DateName>Year end</DateName>
    <DateValue>31/03/2027</DateValue>
  </DateLookup>
  <DateLookup>
    <DateName>Board meeting</DateName>
    <DateValue>14/01/2027</DateValue>
  </DateLookup>
  <HighlightDates>
    <Date>25/12/2026</Date>
    <Date>26/12/2026</Date>
  </HighlightDates>
</CustomDates>

CustomDropDownImage

public Bitmap CustomDropDownImage

Gets or sets the picture drawn on the drop-down button when UseDropDownImageStyle is DropDownImageStyle.CustomImage.

Value
The default is null, which draws the built-in calendar picture.
Remarks

It is drawn at its own size from the button's top-left corner. The button is as wide as a vertical scroll bar and as tall as the text, so a picture of about that size suits it.

CustomFormat

public string CustomFormat

Gets or sets the .NET date format the text is written and read in, such as "dd/MM/yyyy" or "ddd d MMM yyyy".

Value
The default is "D", the culture's long date, set by Format.
Remarks

It takes effect at once, whatever Format says, but setting Format to Long or Short replaces it – so set Format to BinaryDatePickerFormat.Custom as well. Literal text goes in quotes: "MMMM dd yyyy 'at' hh tt" gives March 27 2026 at 09 AM.

DisplayTextState

public bool DisplayTextState

Gets or sets whether the user can type in the text box; the calendar works either way.

Value
true for an editable text box. The default is true.
See also

DotBorderDepth

public int DotBorderDepth

Gets or sets the length of each dash in the text box's dotted border.

Value
In logical pixels. The default is 4.
Remarks

Used while DrawBorderAs is BorderState.Dotted. A value set while EditControlStyleIsExtended is false is ignored.

See also

DotBorderGap

public int DotBorderGap

Gets or sets the space between the dashes of the text box's dotted border.

Value
In logical pixels. The default is 5.
Remarks

Used while DrawBorderAs is BorderState.Dotted. A value set while EditControlStyleIsExtended is false is ignored.

DrawBorderAs

public BorderState DrawBorderAs

Gets or sets whether the text box's border is a continuous line or dotted.

Value
The default is BorderState.Normal, a continuous line.
Remarks

A value set while EditControlStyleIsExtended is false is ignored. A dotted border is drawn with DotBorderDepth and DotBorderGap.

Example
datePicker.DrawBorderAs = BorderState.Dotted;
datePicker.DotBorderDepth = 2;
datePicker.DotBorderGap = 2;
datePicker.BorderColor = Color.SlateGray;

DropWindowIsShowing

public bool DropWindowIsShowing

Gets or sets whether a hosted picker's calendar is open.

Value
Kept up to date only while HostedFromChildContainer is set; otherwise false. Setting it changes nothing on screen.

EditControlStyleIsExtended

public bool EditControlStyleIsExtended

Gets or sets whether the text box has the control's flat, single-line border rather than the standard sunken one.

Value
true for the flat border. The default is true.
Default
true
Remarks

BorderColor, ShowBorderAlways, DrawBorderAs, DotBorderDepth and DotBorderGap apply only while it is set; set it first.

EnableCustomDateXMLFeed

public bool EnableCustomDateXMLFeed

Gets or sets whether typed text is looked up among the named dates in CustomDateXMLFeed.

Value
true to read named dates. The default is false.
Remarks

While it is set, the words today, tomorrow and the rest are not recognised: text that is not a date in the format is looked up in the file instead.

Font

public override Font Font

Gets or sets the font of the date text and of the calendar, which is sized to fit it.

Value
The default is the Windows message box font family at 8.25 points.

ForeColor

public override Color ForeColor

Gets or sets the colour of the date text.

Value
The default is SystemColors.WindowText.
Remarks

The calendar has its own colours; see CalendarForeColor.

Format

public BinaryDatePickerFormat Format

Gets or sets the format the date is written in: the long or short date of the culture, or CustomFormat.

Value
The default is BinaryDatePickerFormat.Long.
Remarks

BinaryDatePickerFormat.Long and BinaryDatePickerFormat.Short set CustomFormat to "D" and "d"; BinaryDatePickerFormat.Custom keeps the format you set there. Typed text is read back in the same format.

HostedFromChildContainer

public bool HostedFromChildContainer

Gets or sets whether the picker is hosted inside another control, such as a grid cell, rather than placed on a form.

Value
The default is false.
Remarks

A hosted picker opens its calendar in a drop-down window rather than a form of its own. Set it before SpecialDates and its colours, which are kept by the calendar this selects.

IsReadOnly

public bool IsReadOnly

Gets or sets whether the date is shown but cannot be changed – neither typed nor picked from the calendar.

Value
true for read-only. The default is false.
Remarks

The calendar still opens, but ignores clicks and keys. DisplayTextState makes only the text read-only; the two set the same text box, so the one set last decides it.

MarkSelectedDate

public bool MarkSelectedDate

Gets or sets whether the calendar marks the chosen day and today with filled circles.

Value
true to mark them. The default is true.
Remarks

While it is false the legend is not drawn either, whatever CalendarLegendDisplay says.

MaxDateTime

public DateTime MaxDateTime

Gets the latest date MaxValue can be set to: 31 December 9999.

MaxValue

public DateTime MaxValue

Gets or sets the latest date the control accepts.

Value
The default is 31 December 9999. A value outside MinDateTime to MaxDateTime is replaced by 31 December 9999. The value read back carries the time of day of Value.
Remarks

A later date set in Value, chosen or committed becomes this date.

MinDateTime

public DateTime MinDateTime

Gets the earliest date MinValue can be set to: 1 February 0001.

MinValue

public DateTime MinValue

Gets or sets the earliest date the control accepts.

Value
The default is 1 February 0001. A value outside MinDateTime to MaxDateTime is replaced by 1 February 0001. The value read back carries the time of day of Value.
Remarks

An earlier date set in Value, chosen in the calendar or committed from the text (Enter, or leaving the control) becomes this date.

See also

NullDateString

public string NullDateString

Gets or sets the text shown when the control holds no date, such as "No date" or "Not shipped".

Value
The default is an empty string.
Remarks

While ValueIsNull is set, Value returns this text unless the control is data bound. Typing it, or clearing the text box, makes the control hold no date.

RenderDropDownButtonWithVisualStyles

public bool RenderDropDownButtonWithVisualStyles

Gets or sets whether the drop-down arrow button is drawn in the Windows visual style, with a hover effect, rather than as a classic combo-box button.

Value
true for the visual style. The default is true.
Remarks

Used while UseDropDownImageStyle is DropDownImageStyle.DropDownArrow, and only when the application has visual styles enabled.

SelectionDateEllipseColor

public Color SelectionDateEllipseColor

Gets or sets the colour of the filled circle marking the chosen day in the calendar.

Value
The default is Color.Blue.
Remarks

Drawn while MarkSelectedDate is set.

SelectionDateForeColor

public Color SelectionDateForeColor

Gets or sets the colour of the chosen day's number in the calendar, drawn on its circle.

Value
The default is Color.Yellow.
See also

ShowBorderAlways

public bool ShowBorderAlways

Gets or sets whether the text box's border is always drawn in BorderColor, rather than only while the pointer is over it or it has the focus.

Value
true for a constant border. The default is true.
Remarks

Set it to false for a hover effect: the border is drawn in a quieter colour at rest. A value set while EditControlStyleIsExtended is false is ignored.

ShowCustomMenu

public bool ShowCustomMenu

Gets or sets whether right-clicking the text box shows the control's own menu.

Value
true for the control's menu. The default is true.
Remarks

The menu has Cut, Copy, Paste, Select All, Clear All, Display Calendar (Ctrl+L) and Quick Dates – yesterday, today, tomorrow, next week and last week. With false the text box's standard menu is shown instead.

ShowDropDownCalendarWindowAfterAdjustingForVirtualAvaliableScreenSpace

public bool ShowDropDownCalendarWindowAfterAdjustingForVirtualAvaliableScreenSpace

Gets or sets whether the calendar opens above the control when there is no room for it below.

Value
true to move it. The default is true.

ShowPopupOnEnter

public bool ShowPopupOnEnter

Gets or sets whether the calendar opens as soon as the control receives the focus.

Value
true to open it on entry. The default is false.
Remarks

The Control.Enter event is raised first, then the calendar opens.

SpecialDates

public DateTime[] SpecialDates

Gets or sets dates to pick out in the calendar – holidays, delivery days, booked dates.

Value
The dates, of which only the day is used. The default is none, or the Date entries of CustomDateXMLFeed once that is set.
Remarks

Each is drawn in SpecialDatesForeColor on SpecialDatesFillColor. The dates go to the calendar HostedFromChildContainer selects, so set that first.

SpecialDatesFillColor

public Color SpecialDatesFillColor

Gets or sets the background of the SpecialDates in the calendar.

Value
The default is SystemColors.ControlDarkDark.

SpecialDatesForeColor

public Color SpecialDatesForeColor

Gets or sets the colour of the day numbers of the SpecialDates in the calendar.

Value
The default is SystemColors.ControlLightLight.

TodayButtonBackColor

public Color TodayButtonBackColor

Gets or sets the background colour of the calendar's Today button.

Value
The default is Control.DefaultBackColor, the standard button colour.
Remarks

Takes effect the next time the calendar opens.

TodayButtonFlatStyle

public FlatStyle TodayButtonFlatStyle

Gets or sets how the calendar's Today button is drawn: flat, popup, standard or by the system.

Value
The default is FlatStyle.Standard.
Remarks

Use FlatStyle.Flat or FlatStyle.Popup for the button colours to show in full.

TodayButtonForeColor

public Color TodayButtonForeColor

Gets or sets the colour of the text on the calendar's Today button.

Value
The default is Control.DefaultForeColor, the standard button text colour.

TodayButtonText

public string TodayButtonText

Gets or sets the caption of the calendar's Today button, which picks today's date and closes the calendar.

Value
The default is "Today".
Remarks

The button is 47 by 20 logical pixels, so keep a translation short – "Heute", "Auj.". The caption is also used on the calendar's right-click menu.

TodayCloseButtonsAreVisible

public bool TodayCloseButtonsAreVisible

Gets or sets whether the calendar shows its Today and Close buttons.

Value
true to show them. The default is true.
Remarks

Without them the calendar is shorter, and offers Today and Close on its right-click menu instead. Takes effect the next time the calendar opens.

TodayEllipseColor

public Color TodayEllipseColor

Gets or sets the colour of the filled circle marking today in the calendar.

Value
The default is Color.Green.
Remarks

Drawn while MarkSelectedDate is set.

TodayForeColor

public Color TodayForeColor

Gets or sets the colour of today's day number in the calendar, drawn on its circle.

Value
The default is Color.Yellow.
See also

UseDropDownImageStyle

public DropDownImageStyle UseDropDownImageStyle

Gets or sets what is drawn on the drop-down button: an arrow, a calendar picture, your own picture, or a glass button.

Value
The default is DropDownImageStyle.DropDownArrow.
See also

Value

public object Value

Gets or sets the date in the control.

Value
A DateTime. The default is today's date. With no date (ValueIsNull) it returns NullDateString, or Value while the control is data bound.
Remarks

Set a DateTime, or null or DBNull for no date; anything else is ignored. A date outside MinValue to MaxValue is moved to the nearer limit. The time of day is kept, and is carried over when the user picks a day.

Check ValueIsNull before casting: with no date the value is not a DateTime.

Example
orderDate.Value = order.OrderedOn;      // a DateTime
shippedDate.Value = null;               // no date yet

if (!shippedDate.ValueIsNull)
{
    order.ShippedOn = (DateTime)shippedDate.Value;
}

ValueIsNull

public bool ValueIsNull

Gets or sets whether the control holds no date, showing NullDateString.

Value
true for no date. The default is false.
Remarks

Clearing the text, or setting Value to null or DBNull, sets it. Setting it back to false shows the date held before, or today.

Methods

Dispose

protected override void Dispose(bool disposing)

Closes and releases the drop-down window of a hosted calendar, then the control.

Parameters
disposing
true when called from Dispose().

OnEnter

protected override void OnEnter(EventArgs e)

Raises the Control.Enter event, then opens the calendar when ShowPopupOnEnter is set.

Parameters
e
The event data.

OnFontChanged

protected override void OnFontChanged(EventArgs e)

Raises the Control.FontChanged event and passes the new font to the calendar.

Parameters
e
The event data.

OnLeave

protected override void OnLeave(EventArgs e)

Commits the typed text as the date when the focus leaves the control, then raises the Control.Leave event.

Parameters
e
The event data.
Remarks

Raises UserDateCustomValidating, then reads the text: in CustomFormat, then through CustomFormatDateChanged or the named dates. Text that cannot be read, or empty text, leaves the control with no date.

OnMouseDown

protected override void OnMouseDown(MouseEventArgs e)

Reads the typed text and, when the press is on the drop-down button, opens the calendar; then raises the Control.MouseDown event.

Parameters
e
The event data.

OnMouseLeave

protected override void OnMouseLeave(EventArgs e)

Raises the Control.MouseLeave event and returns the drop-down button to its resting look.

Parameters
e
The event data.

OnMouseMove

protected override void OnMouseMove(MouseEventArgs e)

Raises the Control.MouseMove event and lights up the drop-down button while the pointer is over it.

Parameters
e
The event data.

OnMouseUp

protected override void OnMouseUp(MouseEventArgs e)

Returns the drop-down button to its resting look, then raises the Control.MouseUp event.

Parameters
e
The event data.

OnPaint

protected override void OnPaint(PaintEventArgs e)

Draws the drop-down button in the UseDropDownImageStyle; the text box draws itself.

Parameters
e
The event data.

OnResize

protected override void OnResize(EventArgs e)

Fits the text box and the drop-down button to the new width, keeps the control as tall as its text, then raises the Control.Resize event.

Parameters
e
The event data.
Remarks

The height follows Font; setting a taller size has no lasting effect.

OnSystemColorsChanged

protected override void OnSystemColorsChanged(EventArgs e)

Raises the Control.SystemColorsChanged event and redraws the control in the new colours.

Parameters
e
The event data.

SelectControlText

public void SelectControlText()

Selects all the text in the control's text box, so the user's next keystroke replaces it.

Events

BinaryCalendarAboutToBeActivated

public event EventHandler BinaryCalendarAboutToBeActivated

Occurs just before the calendar opens.

Remarks

The calendar is a window of its own. On a form whose Form.TopMost is set, clear Form.TopMost here and set it again in BinaryCalendarDeactivated, or the calendar opens behind the form.

BinaryCalendarActivated

public event EventHandler BinaryCalendarActivated

Occurs when the calendar has opened.

See also

BinaryCalendarDeactivated

public event EventHandler BinaryCalendarDeactivated

Occurs when the calendar closes – a day chosen, Today or Close pressed, Escape, or a click elsewhere.

BinaryDateAboutToBeChanged

public event DateChangePreHandler BinaryDateAboutToBeChanged

Occurs as the date is about to change: on each change of the text, when Value is set, and when the null state is set or cleared.

Remarks

The value passed is Value before the change, whether the user types or code sets Value or ValueIsNull.

BinaryDateChanged

public event EventHandler BinaryDateChanged

Occurs whenever the date changes: picked in the calendar, set from code or the menu, stepped by a key, made null – and on each keystroke while the user types.

Remarks

Read Value in the handler; check ValueIsNull first. It is not raised before the control's window exists.

CustomFormatDateChanged

public event CustomFormatDateChangeHandler CustomFormatDateChanged

Occurs when the user leaves the control with text that does not match CustomFormat, so you can interpret it.

Remarks

Raised only while Format is BinaryDatePickerFormat.Custom. The date the handler returns becomes the value; without a handler, unreadable text leaves the control with no date.

MouseIsOverADate

public event MouseOverADateHandler MouseIsOverADate

Occurs as the pointer moves over a day in the calendar, so you can show a tooltip for that date.

Remarks

Raised on each move of the pointer while it is over a day. A tooltip is shown when the handler gives tipInfo body text and does not cancel.

Example
datePicker.MouseIsOverADate += (object sender, DateInfo date, ref bool cancel, ref DateToolTipInfo tip) =>
{
    if (bankHolidays.TryGetValue(date.TheDateMousePointerIsOver.Date, out string name))
    {
        tip.ToolTipTitleText = "Bank holiday";
        tip.ToolTipBodyText = name;
    }
    else
    {
        cancel = true;
    }
};

UserDateCustomValidating

public event CustomValidator UserDateCustomValidating

Occurs before the typed text is read as a date – when the user presses Enter, leaves the control, clicks it or opens the calendar – so you can correct or translate it.

Remarks

The text the handler leaves in dateText replaces the control's text and is then read in CustomFormat.

Example
// Accept "eom" for the end of this month.
datePicker.UserDateCustomValidating += (object sender, ref string text) =>
{
    if (string.Equals(text.Trim(), "eom", StringComparison.OrdinalIgnoreCase))
    {
        DateTime today = DateTime.Today;
        text = new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month))
            .ToString(datePicker.CustomFormat, datePicker.BinaryCultureInfo);
    }
};