An Owner Drawn Calendar Control VB5/6

This code demonstrates how to create your own professional calendar control in VB5/6 - completely customizable with many different styles.

screen-shot

ENVIRONMENT
	This is a VB5 project, which will run under Windows 9x.
	No other than basic VB-controls are used.

YOU CAN LEARN
	Something about making your own controls.
	...
COPYRIGHT
	None. I made the code myself and everybody is free
	to use it.

RUNTIME FILES
	none

CODE FILES
	Calendar.vbg

	stCalendarCtl.vbp/.vbw
		stCalendar.ctl/.ctx

	demo.vbp/.vbw
		frmDemoM.frm
		frmDemoSfrm

	calendar.bmp

Download Zipped Project Files (10k)



Comments

  • Thanks ( and some code )

    Posted by nacnudsco on 02/01/2006 04:51pm

    Thanks dude. Most wonderful. I added the following code.
    '---------------------------------------------------------------------------------------
    ' Procedure : GetSelectedDays
    ' DateTime  : 01/02/2006 16:50
    ' Author    : nacnud
    ' Purpose   : Just get a compressed list of the selected days
    '---------------------------------------------------------------------------------------
    '
    Public Function GetSelectedDays() As Long()
        Dim lngCounter As Long
        Dim selDays() As Long
        For lngCounter = 0 To M_LNG_MAXCONTROL
            If (CellTpe(OffsetCell + lngCounter) = Selected) Then
                '# If we have an uninitilised array
                If (Not selDays) = True Then
                    ReDim Preserve selDays(0)
                Else
                    '# Otherwise, dim on the current size of it.
                    ReDim Preserve selDays(UBound(selDays) + 1)
                End If
                selDays(UBound(selDays)) = lngCounter
            End If
        Next lngCounter
        GetSelectedDays = selDays
    End Function

    Reply
  • Select All and Deselect All for Calendar cells (code in comment)

    Posted by CrimsonGhost on 11/03/2005 02:58pm

    'Add these to your stCalendar.ctl
    
      Public Sub DeselectAll()
    
        Dim I As Integer
    
        For I = LBound(CellTpe) To UBound(CellTpe)
          If CellTpe(I) = Selected Then
            CellTpe(I) = Normal
          End If
        Next I
    
        CalendarRedraw
    
      End Sub
    
      Public Sub SelectAll()
    
        Dim I As Integer
    
        For I = LBound(CellTpe) To UBound(CellTpe)
          If CellTpe(I) = Normal Then
            CellTpe(I) = Selected
          End If
        Next I
    
        CalendarRedraw
    
      End Sub
    
    'In your frmDemoM simply use stCalendar1.SelectAll or stCalendar1.DeselectAll to call your subroutines.  Any non-date cell is ignored.

    Reply
  • Make the demo US compliant (code changes in this comment)

    Posted by CrimsonGhost on 11/03/2005 01:59pm

    'In order to make this demo US calendar 
    'compliant you need to change some code.  
    'Here are the alterations.  NOTE: This 
    'mod is only for frmDemoM, but it should 
    'give you enough to go on.
    
    'In the various subroutines of frmDemoM 
    'find any line that says "lblDate.Caption
    '=..." and replace it with the following.
    'There should be four lines replaced in all.
    'This swaps the dd/mm/yyyy display at the 
    'top of the demo to read mm/dd/yyyy instead.
    
      lblDate.Caption = Format(stCalendar1.cMonth) & "/" & Format(stCalendar1.cDay) & "/" & Format(stCalendar1.cYear)
    
    'In the Form_Load() subroutine look for the 
    '"For I =..." loop and replace the AddItem 
    'line with the following.  It fixes the 
    'drop-down box to display the months correctly.
    'Otherwise if you run it on a US computer
    'it says January 12 times.
    
      cmbMonth.AddItem Format(CDate(I & "/1" & "/2005"), "mmmm")
    
    'Go into the stCalendar user control and the 
    'GetHeaderText() subroutine.  Replace the 
    'line under Case English with the following.  
    'This makes the day of the week row start 
    'with Sunday instead of Monday.
    
      CellTxt(cl) = Left(Choose(cl + 1, "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"), ViewHeaderChar)
    
    'Lastly, under the CalcCalendar() subroutine 
    'replace line with vbMonday to this one.
    'It will realign the calendar to Sunday as the 
    'first day.
    
      FirstDayWD = Weekday(FirstDay, vbSunday)
    
    'That's it!  You should have a US compliant frmDemoM now.

    Reply
  • DblClick sample as requested (code in comment)

    Posted by CrimsonGhost on 11/03/2005 01:38pm

    'Add these items to stCalendar.ctl to enable DblClick on the control:
    
    'Under the variable declarations add:
    
      'Stores MouseMove pointer coordinates
      Dim XX, YY as Integer
    
    'Next add a subroutine for UserControl_MouseMove as follows:
    
      Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        XX = X
        YY = Y
      End Sub
    
    'Finally, add a UserControl_DblClick subroutine.
    
      Private Sub UserControl_DblClick()
         Dim cl As Integer
          
         'Determine what cell was clicked on
         cl = (YY \ szY) * 7 + XX \ szX
       
         'The day number double-clicked is stored in the m_cDay variable by the MouseDown subroutine
       
         'Determine cell type and react accordingly
         Select Case CellTpe(cl)
           Case Header: 'add code here for trapping click on day of the week header
           Case Normal: MsgBox m_cDay & " is unselected." 'display date number in a msgbox
           Case EmptyC: 'clicked on a blank cell
           Case Selected: MsgBox m_cDay & " is selected."
         End Select
      End Sub
    

    Reply
  • stCalendarCtl - Very useful but missing one thing

    Posted by ljwheeler on 07/14/2005 02:31pm

    Let me first thank you for making such a useful control available to those of us who find the Microsoft Calendar Control to be absolutely inadequate.
    
    Secondly, I would like to make a request for one additional event. That event would be named DayDblClicked. Would there be any chance of implementing such an event into your control?
    
    Again, thank you.
    
    Many regards,
    
    LJWheeler

    Reply
  • Nice control, is there a help file or read me?

    Posted by travisreems on 05/24/2004 03:19am

    Nice control, is there a help file or read me?

    Reply
  • Really useful !

    Posted by Legacy on 09/17/2003 12:00am

    Originally posted by: Humberto


    We were having problems with Mscal (the calendar control from Micro$oft) and the stcalendar save us ! It's really useful and flexible.. Even being an example to beginners, I must agree with one who said that it's useful for beginners and advanced users !
    And it's very simple to use !

    Great job !
    Thanks for saving our time !!! :)

    - Humberto -

    Reply
  • GREAT

    Posted by Legacy on 05/15/2003 12:00am

    Originally posted by: McJuke

    fantastic code - thank you!!

    Reply
  • An Owner Drawn Calendar Control VB5/6 - Stefaan Casier

    Posted by Legacy on 01/03/2003 12:00am

    Originally posted by: Jose Pinto

    Sr. Cassier

    He visto algunos de sus trabajos, y debo confesarle que me
    han gustado mucho, al punto que este Calendario junto con el del Reloj, los utilizo para mis proyectos de uso personal
    en mi casa y con mis amigos. Y siento un gran orgullo al comentarles que son de un amigo alem�n.

    Deseo felicitarlo sinceramente, sus trabajos son muy confiables y de buen sentido est�tico.

    Deseo conocer m�s trabajos suyos, ya que estos aportan a mi pobre conocimiento de VB.

    Gracias.

    Jos�

    Reply
  • Great idea!

    Posted by Legacy on 10/09/2002 12:00am

    Originally posted by: Wrenashe

    Good

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds