Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Calendar
  New Posts New Posts RSS Feed - Color-Coding With Office 2007 Theme
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Color-Coding With Office 2007 Theme

 Post Reply Post Reply
Author
Message
jgordon428 View Drop Down
Groupie
Groupie


Joined: 11 June 2009
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote jgordon428 Quote  Post ReplyReply Direct Link To This Post Topic: Color-Coding With Office 2007 Theme
    Posted: 18 October 2010 at 2:48pm
We want to implement color coding of the calendar control in order to be able to show certain times as unavailable. I noticed that this seems doable with the office 2003 theme, but judging from what we've tried and the demo application, this doesn't work with the office 2007 theme. Any way around this with the 2007 theme?
Back to Top
Xander75 View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 April 2007
Status: Offline
Points: 353
Post Options Post Options   Thanks (0) Thanks(0)   Quote Xander75 Quote  Post ReplyReply Direct Link To This Post Posted: 19 October 2010 at 4:11am
Hi jgordon428,

By colour coding the Calendar Control to show certain times as unavailable I believe you mean changing the Calendar cell colours, can you confirm if this is the case?

If so I have done this for displaying the current working week schedule times using the following code in the BeforeDrawThemeObject event:


Private Sub CalendarControl_BeforeDrawThemeObject(ByVal eObjType As XtremeCalendarControl.CalendarBeforeDrawThemeObject, ByVal DrawParams As Variant)
    Dim pCell As CalendarThemeDayViewCellParams
    Set pCell = DrawParams
    Dim pTheme2007 As CalendarThemeOffice2007
    Set pTheme2007 = CalendarControl.Theme

    pTheme2007.DayView.Day.Group.Cell.WorkCell.BackgroundColor = RGB(230, 237, 247)
    pTheme2007.DayView.Day.Group.Cell.WorkCell.BorderBottomInHourColor = RGB(213, 225, 241)
   
    If pCell.Selected Then Exit Sub
   
    If eObjType = xtpCalendarBeforeDraw_DayViewCell Then
        Select Case Weekday(pCell.BeginTime)
            Case "2"    ' Monday
                If TimeValue(pCell.BeginTime) >= AppData.TimeStartMon And TimeValue(pCell.BeginTime) < AppData.TimeFinishMon Then
                    pTheme2007.DayView.Day.Group.Cell.WorkCell.BackgroundColor = RGB(255, 255, 200)
                End If
            Case "3"    ' Tuesday
                If TimeValue(pCell.BeginTime) >= AppData.TimeStartTue And TimeValue(pCell.BeginTime) < AppData.TimeFinishTue Then
                    pTheme2007.DayView.Day.Group.Cell.WorkCell.BackgroundColor = RGB(255, 255, 200)
                End If
            Case "4"    ' Wednesday
                If TimeValue(pCell.BeginTime) >= AppData.TimeStartWed And TimeValue(pCell.BeginTime) < AppData.TimeFinishWed Then
                    pTheme2007.DayView.Day.Group.Cell.WorkCell.BackgroundColor = RGB(255, 255, 200)
                End If
            Case "5"    ' Thursday
                If TimeValue(pCell.BeginTime) >= AppData.TimeStartThu And TimeValue(pCell.BeginTime) < AppData.TimeFinishThu Then
                    pTheme2007.DayView.Day.Group.Cell.WorkCell.BackgroundColor = RGB(255, 255, 200)
                End If
            Case "6"    ' Friday
                If TimeValue(pCell.BeginTime) >= AppData.TimeStartFri And TimeValue(pCell.BeginTime) < AppData.TimeFinishFri Then
                    pTheme2007.DayView.Day.Group.Cell.WorkCell.BackgroundColor = RGB(255, 255, 200)
                End If
            Case "1"    ' Saturday
                If TimeValue(pCell.BeginTime) >= AppData.TimeStartSat And TimeValue(pCell.BeginTime) < AppData.TimeFinishSat Then
                    pTheme2007.DayView.Day.Group.Cell.WorkCell.BackgroundColor = RGB(255, 255, 200)
                End If
            Case "7"    ' Sunday
                If TimeValue(pCell.BeginTime) >= AppData.TimeStartSun And TimeValue(pCell.BeginTime) < AppData.TimeFinishSun Then
                    pTheme2007.DayView.Day.Group.Cell.WorkCell.BackgroundColor = RGB(255, 255, 200)
                End If
            Case Else
                pTheme2007.DayView.Day.Group.Cell.NonWorkCell.BackgroundColor = RGB(230, 237, 247)
        End Select
    End If
End Sub


If you look specifically at the light yellow cell background colour, this is the colour defined as RGB(255, 255, 200) in the code above. As you can see we finish at 1pm on a Friday!!! Wink

Also please note that the "AppData.TimeStartMon" and other "AppData" variables are my own variables to store the date and time for the working day on screen. Just in case you go looking for these! lol


Product: Xtreme SuitePro (ActiveX) v15.3.1
Platform: Windows 7 64-bit (SP1) Professional Edition
Languages: C#.Net using Visual Studio 2012 & Visual Basic 6.0 (SP6)
Back to Top
jgordon428 View Drop Down
Groupie
Groupie


Joined: 11 June 2009
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote jgordon428 Quote  Post ReplyReply Direct Link To This Post Posted: 19 October 2010 at 1:27pm
Thank you so much for your reply, yes, this is exactly what I am looking for. However, one small issue... CalendarControl_BeforeDrawThemeObject is never called. I set a breakpoint there and it is never hit. Something I am missing?

Also, this all seems to be based on the "WorkCell". Does this relate to the properties CalendarControl.Options.WorkDayStartTime and WorkDayEndTime for determining what is a workcell vs nonworkcell? Or is this something different? I noticed for instance that I can set the workday start and end times and it will color code the schedule in a certain way. However, I could not find an option to set this per day, only a single global setting. Looks like your solution would solve this problem. Just not sure if I need to additionally set other properties about what is and is not a workcell.

Thanks again.
Back to Top
dentor View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2005
Location: France
Status: Offline
Points: 102
Post Options Post Options   Thanks (0) Thanks(0)   Quote dentor Quote  Post ReplyReply Direct Link To This Post Posted: 19 October 2010 at 2:58pm
Hello jgordon428,
 
To get the Event BeforeDrawThemeObject to be called, you must set the BeforeDrawThemeObjectFlags property to -1:
 
CalendarControl.BeforeDrawThemeObjectFlags = -1
 
Product: Xtreme SuitePro (ActiveX) version 13.0.0
Platform: Windows XP (32bit) - SP 3
Language: Visual Basic 6.0 SP 6
Back to Top
jgordon428 View Drop Down
Groupie
Groupie


Joined: 11 June 2009
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote jgordon428 Quote  Post ReplyReply Direct Link To This Post Posted: 19 October 2010 at 4:24pm
Very helpful, thank you! I'm getting closer, but still not quite there...

I get a type mismatch error on Set pCell = DrawParams in Xander's example above.

Also, I see the event CalendarControl_BeforeDrawDayViewCell which I think might be another event I can use for the color coding, but again I can't get it to fire. I looked for a property BeforeDrawDayViewCellFlags , but couldn't find one.

I'm using version 13.4.0 of the activeX calendar control.

Thanks for your help!
Back to Top
jgordon428 View Drop Down
Groupie
Groupie


Joined: 11 June 2009
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote jgordon428 Quote  Post ReplyReply Direct Link To This Post Posted: 19 October 2010 at 5:10pm
After a bit of tweaking, I got everything to compile/run, but for some reason it's just coding every day as yellow from 8am-5pm and blue outside that time. Here's what I have so far. Is it something obvious I'm missing? I basically took your code and just made an array to store the start/stop times for each day.

I suppose I don't understand the basic concept. Why is pTheme2007.DayView.Day.Group.Cell.WorkCell the object we want to set the background color of, and not pCell?

Private Sub CalendarControl_BeforeDrawThemeObject(ByVal eObjType As XtremeCalendarControl.CalendarBeforeDrawThemeObject, ByVal DrawParams As Variant)
    Dim TimeStartStopArr() As String
    ReDim TimeStartStopArr(8, 2)

    'Sunday
    TimeStartStopArr(1, 0) = "2:00:00 AM"
    TimeStartStopArr(1, 1) = "4:00:00 PM"
    'Monday
    TimeStartStopArr(2, 0) = "3:00:00 AM"
    TimeStartStopArr(2, 1) = "5:00:00 PM"
    'Tuesday
    TimeStartStopArr(3, 0) = "4:00:00 AM"
    TimeStartStopArr(3, 1) = "6:00:00 PM"
    'Wednesday
    TimeStartStopArr(4, 0) = "5:00:00 AM"
    TimeStartStopArr(4, 1) = "7:00:00 PM"
    'Thursday
    TimeStartStopArr(5, 0) = "6:00:00 AM"
    TimeStartStopArr(5, 1) = "8:00:00 PM"
    'Friday
    TimeStartStopArr(6, 0) = "7:00:00 AM"
    TimeStartStopArr(6, 1) = "9:00:00 PM"
    'Saturday
    TimeStartStopArr(7, 0) = "8:00:00 AM"
    TimeStartStopArr(7, 1) = "10:00:00 PM"


    Dim pTheme2007 As CalendarThemeOffice2007
    Set pTheme2007 = CalendarControl.Theme
     
    If eObjType = CalendarBeforeDrawThemeObject.xtpCalendarBeforeDraw_DayViewCell Then
        
        Dim pCell As CalendarThemeDayViewCellParams
        Set pCell = DrawParams
    
        pTheme2007.DayView.Day.Group.Cell.WorkCell.BackgroundColor = RGB(255, 244, 188)
        pTheme2007.DayView.Day.Group.Cell.WorkCell.BorderBottomInHourColor = RGB(213, 225, 241)
        
        If Not pCell.Selected Then
            If DateDiff("n", TimeValue(DrawParams.BeginTime), TimeStartStopArr(Weekday(DrawParams.BeginTime), 0)) <= 0 And _
               DateDiff("n", TimeValue(DrawParams.BeginTime), TimeStartStopArr(Weekday(DrawParams.BeginTime), 1)) >= 0 Then
                
                pTheme2007.DayView.Day.Group.Cell.WorkCell.BackgroundColor = RGB(255, 255, 213)
        
            End If
        End If
    End If
End Sub
Back to Top
jgordon428 View Drop Down
Groupie
Groupie


Joined: 11 June 2009
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote jgordon428 Quote  Post ReplyReply Direct Link To This Post Posted: 19 October 2010 at 6:52pm
Well, this seemed to solve it:

CalendarControl.Options.WorkDayStartTime = #12:00:00 AM#
CalendarControl.Options.WorkDayEndTime = #11:59:59 PM#

I guess the default values of 8-5 were overriding the custom theme colors. Everything is working now. Thanks to both of you for your help.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.