BinaryDatePicker
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 | |
|---|---|
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 | Gets or sets the background of the text box. |
BinaryCultureInfo | Gets or sets the culture the date is written, read and shown in – month and day names, the long and short date formats. |
BorderColor | Gets or sets the colour of the text box's border. |
CalendarForeColor | Gets or sets the colour of the day numbers, the day names and the legend text in the calendar. |
CalendarInactiveDateForeColor | Gets or sets the colour of the days of the previous and next months that fill the calendar's first and last rows. |
CalendarLegendDisplay | Gets or sets whether the calendar shows a legend under the days, explaining the Today and Selection circles. |
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. |
CalendarMonthBackColor | Gets or sets the background of the calendar. |
CalendarMonthTitleForeColor | Gets or sets the colour of the month and year in the calendar's title. |
CalenderDropDownArrowGlassRenderingColor | Gets or sets the colour of the arrow on the glass drop-down button. |
CalenderDropDownGlassRenderingEndColor | Gets or sets the dark colour of the glass drop-down button, also used for its outline. |
CalenderDropDownGlassRenderingStartColor | Gets or sets the light colour of the glass drop-down button. |
CloseButtonBackColor | Gets or sets the background colour of the calendar's Close button. |
CloseButtonFlatStyle | Gets or sets how the calendar's Close button is drawn: flat, popup, standard or by the system. |
CloseButtonForeColor | Gets or sets the colour of the text on the calendar's Close button. |
CloseButtonText | Gets or sets the caption of the calendar's Close button, which closes the calendar without changing the date. |
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. |
CustomDropDownImage | Gets or sets the picture drawn on the drop-down button when UseDropDownImageStyle is DropDownImageStyle.CustomImage. |
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". |
DisplayTextState | Gets or sets whether the user can type in the text box; the calendar works either way. |
DotBorderDepth | Gets or sets the length of each dash in the text box's dotted border. |
DotBorderGap | Gets or sets the space between the dashes of the text box's dotted border. |
DrawBorderAs | Gets or sets whether the text box's border is a continuous line or dotted. |
DropWindowIsShowing | Gets or sets whether a hosted picker's calendar is open. |
EditControlStyleIsExtended | Gets or sets whether the text box has the control's flat, single-line border rather than the standard sunken one. |
EnableCustomDateXMLFeed | Gets or sets whether typed text is looked up among the named dates in CustomDateXMLFeed. |
Font | Gets or sets the font of the date text and of the calendar, which is sized to fit it. |
ForeColor | Gets or sets the colour of the date text. |
Format | Gets or sets the format the date is written in: the long or short date of the culture, or CustomFormat. |
HostedFromChildContainer | Gets or sets whether the picker is hosted inside another control, such as a grid cell, rather than placed on a form. |
IsReadOnly | Gets or sets whether the date is shown but cannot be changed – neither typed nor picked from the calendar. |
MarkSelectedDate | Gets or sets whether the calendar marks the chosen day and today with filled circles. |
MaxDateTime | Gets the latest date MaxValue can be set to: 31 December 9999. |
MaxValue | Gets or sets the latest date the control accepts. |
MinDateTime | Gets the earliest date MinValue can be set to: 1 February 0001. |
MinValue | Gets or sets the earliest date the control accepts. |
NullDateString | Gets or sets the text shown when the control holds no date, such as "No date" or "Not shipped". |
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. |
SelectionDateEllipseColor | Gets or sets the colour of the filled circle marking the chosen day in the calendar. |
SelectionDateForeColor | Gets or sets the colour of the chosen day's number in the calendar, drawn on its circle. |
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. |
ShowCustomMenu | Gets or sets whether right-clicking the text box shows the control's own menu. |
ShowDropDownCalendarWindowAfterAdjustingForVirtualAvaliableScreenSpace | Gets or sets whether the calendar opens above the control when there is no room for it below. |
ShowPopupOnEnter | Gets or sets whether the calendar opens as soon as the control receives the focus. |
SpecialDates | Gets or sets dates to pick out in the calendar – holidays, delivery days, booked dates. |
SpecialDatesFillColor | Gets or sets the background of the SpecialDates in the calendar. |
SpecialDatesForeColor | Gets or sets the colour of the day numbers of the SpecialDates in the calendar. |
TodayButtonBackColor | Gets or sets the background colour of the calendar's Today button. |
TodayButtonFlatStyle | Gets or sets how the calendar's Today button is drawn: flat, popup, standard or by the system. |
TodayButtonForeColor | Gets or sets the colour of the text on the calendar's Today button. |
TodayButtonText | Gets or sets the caption of the calendar's Today button, which picks today's date and closes the calendar. |
TodayCloseButtonsAreVisible | Gets or sets whether the calendar shows its Today and Close buttons. |
TodayEllipseColor | Gets or sets the colour of the filled circle marking today in the calendar. |
TodayForeColor | Gets or sets the colour of today's day number in the calendar, drawn on its circle. |
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 | Gets or sets the date in the control. |
ValueIsNull | Gets or sets whether the control holds no date, showing NullDateString. |
| Methods | |
Dispose | Closes and releases the drop-down window of a hosted calendar, then the control. |
OnEnter | Raises the Control.Enter event, then opens the calendar when ShowPopupOnEnter is set. |
OnFontChanged | Raises the Control.FontChanged event and passes the new font to the calendar. |
OnLeave | Commits the typed text as the date when the focus leaves the control, then raises the Control.Leave event. |
OnMouseDown | Reads the typed text and, when the press is on the drop-down button, opens the calendar; then raises the Control.MouseDown event. |
OnMouseLeave | Raises the Control.MouseLeave event and returns the drop-down button to its resting look. |
OnMouseMove | Raises the Control.MouseMove event and lights up the drop-down button while the pointer is over it. |
OnMouseUp | Returns the drop-down button to its resting look, then raises the Control.MouseUp event. |
OnPaint | Draws the drop-down button in the UseDropDownImageStyle; the text box draws itself. |
OnResize | 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. |
OnSystemColorsChanged | Raises the Control.SystemColorsChanged event and redraws the control in the new colours. |
SelectControlText | Selects all the text in the control's text box, so the user's next keystroke replaces it. |
| Events | |
BinaryCalendarAboutToBeActivated | Occurs just before the calendar opens. |
BinaryCalendarActivated | Occurs when the calendar has opened. |
BinaryCalendarDeactivated | Occurs when the calendar closes – a day chosen, Today or Close pressed, Escape, or a click elsewhere. |
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. |
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. |
CustomFormatDateChanged | Occurs when the user leaves the control with text that does not match CustomFormat, so you can interpret it. |
MouseIsOverADate | Occurs as the pointer moves over a day in the calendar, so you can show a tooltip for that date. |
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. |
Constructors
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
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
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.nullalso 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
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
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
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
Gets or sets whether the calendar shows a legend under the days, explaining the Today and Selection circles.
- Value
trueto show it. The default istrue.
Remarks
The legend is drawn only while MarkSelectedDate is also set; without it the calendar is shorter.
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
Gets or sets the background of the calendar.
- Value
- The default is
SystemColors.Window.
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
Gets or sets the colour of the arrow on the glass drop-down button.
- Value
- The default is
SystemColors.ControlDarkDark.
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
Gets or sets the light colour of the glass drop-down button.
- Value
- The default is
SystemColors.Window.
Remarks
Used while UseDropDownImageStyle is DropDownImageStyle.GlassRendering.
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
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
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
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
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
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
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 byFormat.
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
Gets or sets whether the user can type in the text box; the calendar works either way.
- Value
truefor an editable text box. The default istrue.
See also
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
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
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
Gets or sets whether a hosted picker's calendar is open.
- Value
- Kept up to date only while
HostedFromChildContaineris set; otherwisefalse. Setting it changes nothing on screen.
EditControlStyleIsExtended
Gets or sets whether the text box has the control's flat, single-line border rather than the standard sunken one.
- Value
truefor the flat border. The default istrue.- Default
true
Remarks
BorderColor, ShowBorderAlways, DrawBorderAs,
DotBorderDepth and DotBorderGap apply only while it is set; set it first.
EnableCustomDateXMLFeed
Gets or sets whether typed text is looked up among the named dates in CustomDateXMLFeed.
- Value
trueto read named dates. The default isfalse.
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
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
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
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
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
Gets or sets whether the date is shown but cannot be changed – neither typed nor picked from the calendar.
- Value
truefor read-only. The default isfalse.
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
Gets or sets whether the calendar marks the chosen day and today with filled circles.
- Value
trueto mark them. The default istrue.
Remarks
While it is false the legend is not drawn either, whatever CalendarLegendDisplay says.
MaxDateTime
Gets the latest date MaxValue can be set to: 31 December 9999.
MaxValue
Gets or sets the latest date the control accepts.
- Value
- The default is 31 December 9999. A value outside
MinDateTimetoMaxDateTimeis replaced by 31 December 9999. The value read back carries the time of day ofValue.
Remarks
A later date set in Value, chosen or committed becomes this date.
MinDateTime
Gets the earliest date MinValue can be set to: 1 February 0001.
MinValue
Gets or sets the earliest date the control accepts.
- Value
- The default is 1 February 0001. A value outside
MinDateTimetoMaxDateTimeis replaced by 1 February 0001. The value read back carries the time of day ofValue.
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
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
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
truefor the visual style. The default istrue.
Remarks
Used while UseDropDownImageStyle is DropDownImageStyle.DropDownArrow, and only when
the application has visual styles enabled.
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
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
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
truefor a constant border. The default istrue.
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.
ShowDropDownCalendarWindowAfterAdjustingForVirtualAvaliableScreenSpace
Gets or sets whether the calendar opens above the control when there is no room for it below.
- Value
trueto move it. The default istrue.
ShowPopupOnEnter
Gets or sets whether the calendar opens as soon as the control receives the focus.
- Value
trueto open it on entry. The default isfalse.
Remarks
The Control.Enter event is raised first, then the calendar opens.
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
Dateentries ofCustomDateXMLFeedonce that is set.
Remarks
Each is drawn in SpecialDatesForeColor on SpecialDatesFillColor. The dates go to
the calendar HostedFromChildContainer selects, so set that first.
SpecialDatesFillColor
Gets or sets the background of the SpecialDates in the calendar.
- Value
- The default is
SystemColors.ControlDarkDark.
SpecialDatesForeColor
Gets or sets the colour of the day numbers of the SpecialDates in the calendar.
- Value
- The default is
SystemColors.ControlLightLight.
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
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
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
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
Gets or sets whether the calendar shows its Today and Close buttons.
- Value
trueto show them. The default istrue.
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
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
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
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
Gets or sets the date in the control.
- Value
- A
DateTime. The default is today's date. With no date (ValueIsNull) it returnsNullDateString, orValuewhile 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
Gets or sets whether the control holds no date, showing NullDateString.
- Value
truefor no date. The default isfalse.
Remarks
Methods
Dispose
Closes and releases the drop-down window of a hosted calendar, then the control.
Parameters
disposingtruewhen called fromDispose().
OnEnter
Raises the Control.Enter event, then opens the calendar when ShowPopupOnEnter is set.
Parameters
e- The event data.
OnFontChanged
Raises the Control.FontChanged event and passes the new font to the calendar.
Parameters
e- The event data.
OnLeave
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
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
Raises the Control.MouseLeave event and returns the drop-down button to its resting look.
Parameters
e- The event data.
OnMouseMove
Raises the Control.MouseMove event and lights up the drop-down button while the pointer is over it.
Parameters
e- The event data.
OnMouseUp
Returns the drop-down button to its resting look, then raises the Control.MouseUp event.
Parameters
e- The event data.
OnPaint
Draws the drop-down button in the UseDropDownImageStyle; the text box draws itself.
Parameters
e- The event data.
OnResize
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
Raises the Control.SystemColorsChanged event and redraws the control in the new colours.
Parameters
e- The event data.
SelectControlText
Selects all the text in the control's text box, so the user's next keystroke replaces it.
Events
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
Occurs when the calendar has opened.
See also
BinaryCalendarDeactivated
Occurs when the calendar closes – a day chosen, Today or Close pressed, Escape, or a click elsewhere.
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
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
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
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
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);
}
};