If you have any tips to contribute, email us at firstname.lastname@example.org. Be sure to include instructions and source code. For each tip received which gets published we will pay you $10 to $25 US Dollars.
In this issue we discuss how to create your own calendar control.
If you have any questions about using this module, let us know at email@example.com
There are many calendar controls on the market these days. Most of those controls do not include source code to modify if the control does not quite perform the function you want it to. This calendar control is also pretty lightweight. Most of the work occurs in a single routine called RedrawCalendar. It does not depend on anything other than the Visual Basic run time libraries (ie no third party controls).
This control contains the basic logic to create a language independent calendar with the ability to view a month at a time. It can easily be used in a control array to view multiple months at a time.
One limitation we took was with the Font properties. Instead of using the full font object we just allowed setting the FontSize and FontName. Of course you can enhance this to include additional properties.
There are many ways this control can be enhanced. If an enhanced version of this control would be useful to you, please email us at firstname.lastname@example.org
Public Property Let BackColor(lBackColor As Long)
Allows the setting of the background color for the calendar. The standard colors such as vbWhite, vbRed, etc can be used. Thr RGB function can also be used here.
Public Property Get FontName() As String Public Property Let FontName(sFontName As String)
The name of the font to use when drawing the numbers and text in the calendar.
Public Property Let FontSize(lFontSize As Long) Public Property Get FontSize() As Long
The size of the font to use when drawing the numbers and the text in the calendar.
Public Property Let Month(lMonth As Long) Public Property Get Month() As Long
The number of the month to show. It should be in the range of 1 for January and 12 for December.
Public Property Let Year(lYear As Long) Public Property Get Year() As Long
The number of the year to show. It will support from January 1, 100 to December 31, 9999 (based on the Visual Basic documentation).
Public Sub RedrawCalendar()
Forces the calendar to be redrawn. In general this should not need to be called. It will be called automatically when properties change that would affect the calendar (such as changing the month).
Public Sub NextMonth()
Changes the calendar to show the next month.
Public Sub PreviousMonth()
Changes the calendar to show the previous month.
This sample shows how to use the calendar control. There really is nothing more to do than to drop the calendar control on a form and set the properties appropriately. This example assumes the calendar control is called oCal.
oCal.Month = 9 oCal.Year = 2000 ' will force the calendar to display the calendar for September 2000.
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0126.html