DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Calender control

    [Originally posted by VRK]

    Hi,
    I am developing a vb6 application. I want to show a calender control with icon (may be check boxes or cross) in the day part. If user clicks in that particular day then the picture will be displayed in the cell. How to achieve this. Please help.

    regards

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Calender control

    [Originally posted by Greg DeBacker]

    Here is some simple code i wrote to draw a month view on a form or picturebox. Maybe you will find some use in it...

    Private Sub Form_Paint()
    ˙ ˙ DrawCal Me, "2002", "4"
    End Sub

    Private Sub DrawCal(DrawOn As Object, sYear As String, sMonth As String)
    ˙ ˙ 'You can change 'As Object' to 'As Form' or 'As PictureBox'
    ˙ ˙ 'if you know what you will be drawing to
    ˙ ˙ Dim k As Long
    ˙ ˙ Dim i As Long
    ˙ ˙ Dim iBoxWidth As Long
    ˙ ˙ Dim iBoxHeight As Long
    ˙ ˙ Dim iStart As Long
    ˙ ˙ Dim iDays As Long
    ˙ ˙ Dim sTemp As String
    ˙ ˙ Dim iDaySpot˙ As Integer
    ˙ ˙ Dim iRow As Integer
    ˙ ˙
    ˙ ˙ DrawOn.Cls
    ˙ ˙
    ˙ ˙ 'Draw month and year
    ˙ ˙ DrawOn.CurrentX = 80
    ˙ ˙ DrawOn.CurrentY = 100
    ˙ ˙ DrawOn.Print Format$(DateValue(sMonth & "/1/" & sYear), "mmmm yyyy")

    ˙ ˙ 'Get the width and height of each box
    ˙ ˙ iBoxWidth = (DrawOn.ScaleWidth - 20) / 7
    ˙ ˙ iBoxHeight = (DrawOn.ScaleHeight - 1000) / 6
    ˙ ˙ For k = 0 To 6
    ˙ ˙ ˙ ˙ 'Draw days on top line
    ˙ ˙ ˙ ˙ DrawOn.CurrentX = iBoxWidth * k + 80
    ˙ ˙ ˙ ˙ DrawOn.CurrentY = 800 - DrawOn.TextHeight("A") - 60
    ˙ ˙ ˙ ˙ DrawOn.Print Format$(DateValue("12/29/2002") + k, "dddd")
    ˙ ˙ ˙ ˙ 'draw the boxes
    ˙ ˙ ˙ ˙ For i = 0 To 5
    ˙ ˙ ˙ ˙ ˙ ˙ DrawOn.Line (iBoxWidth * k, (iBoxHeight * i) + 800)-(iBoxWidth * k + iBoxWidth, iBoxHeight * i + iBoxHeight + 800), , B
    ˙ ˙ ˙ ˙ Next
    ˙ ˙ Next
    ˙ ˙
    ˙ ˙ 'get the first day of the month
    ˙ ˙ sTemp = (Format$(DateSerial(sYear, sMonth, 1), "ddd"))
    ˙ ˙ Select Case LCase$(sTemp)
    ˙ ˙ ˙ ˙ Case "sun": iStart = 0
    ˙ ˙ ˙ ˙ Case "mon": iStart = 1
    ˙ ˙ ˙ ˙ Case "tue": iStart = 2
    ˙ ˙ ˙ ˙ Case "wed": iStart = 3
    ˙ ˙ ˙ ˙ Case "thu": iStart = 4
    ˙ ˙ ˙ ˙ Case "fri": iStart = 5
    ˙ ˙ ˙ ˙ Case "sat": iStart = 6
    ˙ ˙ End Select
    ˙ ˙
    ˙ ˙ 'Figure the number of days in the month
    ˙ ˙ sTemp = Format$(DateSerial(sYear, sMonth, 1), "m")
    ˙ ˙ For k = 1 To 5
    ˙ ˙ ˙ ˙ If sTemp <> Format$(DateSerial(sYear, sMonth, 27 + k), "m") Then
    ˙ ˙ ˙ ˙ ˙ ˙ iDays = 27 + k - 1
    ˙ ˙ ˙ ˙ ˙ ˙ Exit For
    ˙ ˙ ˙ ˙ End If
    ˙ ˙ Next
    ˙ ˙
    ˙ ˙ 'draw the dates
    ˙ ˙ iDaySpot = iStart - 1
    ˙ ˙ iRow = 1
    ˙ ˙ For k = iStart To iStart + iDays - 1
    ˙ ˙ ˙ ˙ iDaySpot = iDaySpot + 1
    ˙ ˙
    ˙ ˙ ˙ ˙ If iDaySpot > 6 Then
    ˙ ˙ ˙ ˙ ˙ ˙ iRow = iRow + 1
    ˙ ˙ ˙ ˙ ˙ ˙ iDaySpot = 0
    ˙ ˙ ˙ ˙ End If
    ˙ ˙
    ˙ ˙ ˙ ˙ DrawOn.CurrentX = (iBoxWidth * iDaySpot) + ((iBoxWidth - DrawOn.TextWidth(Trim$(Str$(k)))) / 2)
    ˙ ˙ ˙ ˙ DrawOn.CurrentY = ((iBoxHeight * iRow) + 800) - (iBoxHeight / 2)
    ˙ ˙ ˙ ˙ DrawOn.Print Trim$(Str$(k - iStart + 1))
    ˙ ˙ Next

    End Sub

    Grex

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links