ctl32_datepicker
This visual class provides a datepicker control that can be used in VFP9. This class uses the Windows API to create a true Windows Common Controls monthcalendar, with full Themes compliance, just a couple of files to add to your project, No DLLs, no FLLs, no OCXs.
Known limitations: The control cannot be used in a grid. The dropdown monthcalendar needs form space to display, if it does not have space to the right/under the control, it will display at the top/left of the control.
The following files should be added to your project, copy all the files to the same folder:
ctl32.h
ctl32.prg
ctl32_api.prg
ctl32_functions.prg
ctl32_structures.prg
ctl32.vct
ctl32.vcx
ctl32.prg
ctl32_api.prg
ctl32_functions.prg
ctl32_structures.prg
ctl32.vct
ctl32.vcx
This control uses a standard VFP combobox and a ctl32_monthcalendar control to emulate a DateTimePicker control, but without the time part, just for dates.
ctl32_datepicker control in Windows XP (font set to Tahoma 8pt)
The control uses the current VFP format for dates, controlled by SET SYSFORMATS, SET DATE, SET CENTURY, SET MARK.
Changing the date
The date in the ctl32_datepicker control can be changed in many ways, using the keyboard or the mouse.
To enter a date, the 0 to 9 keys, and any of the keys in the numeric keypad to enter a separator, like ".", "/" or "*".
A date can be entered just using numbers:
1 digit: 1 digit day, the current month and year are appended: 2 -> 02/06/2008 (DMY) or 06/02/2008 (MDY) or 2008/06/02 (YMD)
2 digits: 2 digit day, the current month and year are appended: 23 -> 23/06/2008 (DMY) or 06/23/2008 (MDY) or 2008/06/23 (YMD)
If the 2 digit number entered is > last day of current month (28,29,30,31) then the control assumes a one digit day and a one digit month.
3 digits: best guess at day and month.
4 digits: 2 digit day, 2 digit month, the current year is appended: 0507 -> 05/07/2008
5 digits: 2 digit day, 2 digit month, 1 digit year: 05079 -> 05/07/2009
6 digits: 2 digit day, 2 digit month, 2 digit year
7 digits: 2 digit day, 2 digit month, 3 digit year
8 digits: 2 digit day, 2 digit month, 4 digit year
The ".", "/", "*", "-" keys can be used as the date separator mark, they will be converted to the current date mark.
The date is validated in the LostFocus event, if an invalid date was entered, the date is corrected to the nearest possible date, with a warning beep. If the date cannot be corrected to a possible date, then it is left empty.
LEFT ARROW, RIGHT ARROW:
Month calendar drop down closed: moves the cursor position.
Month calendar drop down open: move the selected day highlight left/right.
UP ARROW, DOWN ARROW:
Month calendar dropdown closed: Increment/decrement the date by one day if the whole date is selected. Increment/decrement the date by one day if the cursor is on the day part or the day is selected, increment/decrement the date by one month if the cursor is on the month part or the month is selected, increment/decrement the date by one year if the cursor is on the year part or the year is selected.
Month calendar drop down open: move the selected day highlight up/down.
PAGE UP, PAGE DOWN:
Increment/decrement the date by one month.
CTRL + PAGE UP, CTRL + PAGE DOWN:
Increment/decrement the date by one year.
HOME:
Select first day of the month.
END:
Select last day of the month
CTRL + HOME:
Select today´s date.
SPACE:
Open/close the dropdown month calendar.
ALT + DOWN ARROW:
Open/close the dropdown month calendar.
ctl32_datepicker in Windows Vista
With the mouse/mouse wheel:
The mouse cursor must be positioned inside the control textbox for the mouse wheel to work.
If the whole date is selected, the mouse wheel increments/decrements the date by one day.
If the day part of the date is selected, or the cursor is in the day part of the date, the mouse wheel increments/decrements the date by one day.
If the month part of the date is selected, or the cursor is in the month part of the date, the mouse wheel increments/decrements the date by one month.
If the year part of the date is selected, or the cursor is in the year part of the date, the mouse wheel increments/decrements the date by one year.
In the month calendar dropdown, clicking a date sets the date to the selected date. Double clicking a date sets the date to the selected date and closes the month calendar drop down.
ctl32_datepicker in Windows 2000
Empty dates can be entered by just clearing the textbox portion of the control.
The control can be bound by using the ctlControlSource property. DO NOT use the ControlSource property, since VFP comboboxes cannot be bound to a date type field/property/variable.
ctl32_datepicker in Windows 98
The ctlValueChanged event fires every time the date value changes. The date value can be set/retrieved in the ctlValue property.
No comments:
Post a Comment