Calendar Control

Properties	Methods	Events

Description

The calendar control is a sub-classed container control.  The control dynamically adds and autosizes all of its buttons, fonts, labels, etc. to fit within any arbitrarily specified size.  Provision is made for easily setting the font, and colors used for the controls.  In addition, the control supports multi-selecting dates and selecting date ranges.  A sample form with some calendar controls inserted is shown below.

Usage

To use the control, insert it on your control.  At design time, the calendar is not drawn.  The buttons will be added at run time.  Size the control to fit in the area available on your form.  Set the optional properties listed below.

Properties

AllowMultiSelect

If this property is set to .T., then the users will be able to select multiple days.  To select a range, mark one date, and then press SHIFT while clicking on the next day.  The range of dates will be marked.  To multiselect individual days, press CTRL while clicking on a day button.  The range algorithm goes from the nearest currently marked date to the new ending date.

aSelected[ ]

This is a an array property.  It will contain one row for each date selected on the calendar.  If you want to pre-select your own dates, you can populate this array, and then call SetupDisplay() with the initial desired date to display.

DayAbbrevChars

This property sets how many characters will be used on the Day label buttons.  The default value is 3 (i.e. Mon, Tue, Wed, etc).  If the calendar is going to be small, you may want to set this value to 1.

DisplayDate

The date the calendar was asked most recently to display.  This value is not necessarily the first day of the month.

dMaximum

The maximum allowed date the calendar can display.  The default value is 12/31/99.

dMaxSelected

The highest date selected on the calendar.  If Allow multi-select is set to .f., this is the same as .Value.

dMinimum

The minimum allowed date the calendar can display.  The default value is 1/1/80.

dMinSelected

The lowest or earliest date selected on the calendar.

ShowWeekends

If .T., columns for Saturday and Sunday are displayed.  If .F., they are not shown.

Value

Date that was most recently selected, or de-selected.

Methods

Init( dStart )

The Init() method accepts as a parameter the date to be displayed.

SetupDisplay( dDate )

This method sets up the calendar to display the specified date.

Events

DaySelectEvent( oCalDay )

This is an internal function. It accepts as a parameter a CalDay object.  It is recommended that you attach your code to the OnDaySelect or OnDayDeSelect events.

OnDaySelect( dSelected )

This event is fired any time a day is selected.  It is passed the date selected as a variable of type DATE.

OnDayDeSelect( dDeSelected )

This event is fired any time a day is de-selected.  It is passed the date de-selected as a variable of type DATE.

Notes

To set the font that is used, insert the control, and then right click.  From the menu choose EDIT.  Now, click on the EditBox control contained in the control.  Set the font and color properties for the calendar on the edit control.  When the control is initialized, it uses these values.

You might notice that when instantiated, the control is a touch smaller than at design-time.  This is because the calendar control auto sizes itself.  This minor size-adjustment is necessary to prevent banding in between the button controls as they are drawn.

If ShowWeekends is .T., then the height should be a multiple of 9, and the width should be a multiple of 28.

If ShowWeekends is .F., then the height should be a multiple of 8, and the width should be a multiple of 20.

If the conditions listed above are not met, then the control will size itself to meet them.


Contents

YACC, as its title implies, is a calendar class for Microsoft Visual FoxPro.  The library consists of three primary classes you can use in your programs.  And now without further ado, they are:

txtDate Control

txtDateTime Control

Calendar Control

Copyright Notice, Licensing & Liability

This work is not copyrighted.  You may use this software for any purpose without payment of fee or licensing.  If you publish it in a book it would be nice to be listed in the credits.  Under no circumstances shall the liability of MH Software or Author exceed the amount paid for the software.  It is entirely up to the user to determine the fitness for use of this software.

About The Author

George Sexton is the president of MH Software, a company specializing in Software Tool development.    He is a two-time winner of the Microsoft MVP award, and the author of several magazine articles on FoxPro programming.  He can be contacted via CompuServe at 73237,1665.


txtDate Control

Description

txtDate is a sub-classed text box.  The major difference is in that the KeyPress Event has been heavily modified to add keyboard increment and decrement of the date.  In addition, right-clicking on the control will bring up a form to allow the user to select the date from a calendar.

Usage

Use this control on forms in place of the TextBox control when you need to handle date input.

Notes

Custom Properties

lWeekDaysOnly

If this property is set to .T., the control will only permit entry of dates that fall on week days.  If the date is manually entered, and is a weekend, the LostFocus() method will call IncrementValue() to move the date onto a weekday.

Keyboard Map

The table below shows the re-mapped keys that are active when the txtDate control has focus.

Key	Description
+	Increment the date by one day.  If the current date is a null date, set the current value to todays date.
-	Decrement the date by one day.  If the current value is a null date, set the value to todays date.
PgUp	Decrement the date by one month.
PgDn	Increment the date by one month.
CtrlPgDn	Increment the date by one year.
CtrlPgUp	Decrement the date by one year.
? RightClick	Invoke a popup calendar (shown below) to get the date from.


txtDateTime Control

Description

txtDateTime is a sub-classed text box.  The major difference is in that the KeyPress Event has been heavily modified to add keyboard increment and decrement of the date and time.  In addition, right-clicking on the control will bring up a form to allow the user to select the date and time from a calendar.

Usage

Use this control on forms in place of the TextBox control when you need to handle datetime input.

Notes

Custom Properties

lWeekDaysOnly

If this property is set to .T., the control will only permit entry of dates that fall on week days.  If the date is manually entered, and is a weekend, the LostFocus() method will call IncrementValue() to move the date onto a weekday.

Keyboard Map

The table below shows the re-mapped keys that are active when the txtDate control has focus.

Key	Description
.	Increment the time value by 15 minutes.
,	Decrement the time value by 15 minutes.
>	Increment the time value by 1 hour.
<	Decrement the time value by one hour.
(SPACE)	Truncate the minutes stored in the current time.
+	Increment the date by one day.  The the current date is a null date, set the current value to todays date.
-	Decrement the date by one day.  If the current value is a null date, set the value to todays date.
PgUp	Decrement the date by one month.
PgDn	Increment the date by one month.
CtrlPgDn	Increment the date by one year.
CtrlPgUp	Decrement the date by one year.
? RightClick	Invoke a popup calendar (shown below) to get the date from.