Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Custom draw to color specific cells (Read 4847 times)
john6630
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 74
Joined: Sep 20th, 2010
Custom draw to color specific cells
Feb 13th, 2011 at 11:52pm
Print Post  
I have found that the best way to learn MinsFusion is by reading the old posts here (and of course, asking Meppy!). So I thought it would be useful to share the code I created from Meppy's sample so that others can benefit and also, ask for any suggestion to improve it.

My need is to color cells according to whether they are work hours or not. I also want to allow for work days that may include week ends. And to handle work days that span calendar dates (ie. go past midnight). My code colors the non-working cells a light gray. The code below works for my needs with a couple of short comings -
(1) I have to have each calendar start on the whole hour closest to the start time of the work day (this to get the time line grouping to display as I want it to (see my earlier posts). This does not color the cell or cells at the start of the day which are not part of the work day due to the hourly start requirement.
(2) If the cell time is larger than the minutes of the work time (e.g. cell time 60 minutes and the work time ends at 7:30, it does not allow for coloring half a cell). This is one I would like to fix if anyone can tell me how.

Here is my code in VB.Net:
Private Sub calendar_Draw(ByVal sender As Object, _
ByVal e As MindFusion.Scheduling.WinForms.DrawEventArgs) Handles calendar.Draw
If e.Element = CustomDrawElements.TimetableCell Then
Dim cellStart As DateTime = e.Date.Add(e.StartTime)
Dim cellEnd As DateTime = cellStart.Add(_calendar.TimetableSettings.CellTime)
Dim localWorkEnd As New TimeSpan
' allow for day run past midnight
If workEndTime < workStartTime Then
localWorkEnd = workEndTime.Add(New TimeSpan(24, 0, 0))
Else
localWorkEnd = workEndTime
End If
Dim cellEndLimit As DateTime = e.Date.Add(localWorkEnd)
If cellStart < cellEndLimit AndAlso _
theWeekDayCode.IndexOf(e.Date.DayOfWeek) >= 0 Then
' a work period so no coloring
Exit Sub
End If
Dim b As Rectangle = e.Bounds
Dim g As MindFusion.Drawing.IGraphics = e.Graphics
Dim p As New Pen(e.Style.LineColor, 0)
Dim b2 As New SolidBrush(Color.WhiteSmoke)
g.FillRectangle(b2, b)
g.DrawLine(p, b.Left, b.Top, b.Left, b.Bottom - 1)
g.DrawLine(p, b.Right - 1, b.Top, b.Right - 1, b.Bottom - 1)
g.DrawLine(p, b.Left, b.Top, b.Right - 1, b.Top)
g.DrawLine(p, b.Left, b.Bottom - 1, b.Right - 1, b.Bottom - 1)
End If
End Sub

And the code to activiate the custom draw event:
calendar.CustomDraw = MindFusion.Scheduling.WinForms.CustomDrawElements.TimetableCell

Any comments or improvements greatly appreciated. I also encourage others to post key code so we can all benefit. This is a great tool but the learning curve can be difficult.

John
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Custom draw to color specific cells
Reply #1 - Feb 14th, 2011 at 7:26am
Print Post  
You can use the TimetableSettings.WorkTimeCellStyle style to customize the appearance of the cells in the work time. The following code will cause work time cells to be painted in WhiteSmoke:

Code
Select All
_calendar.TimetableSettings.WorkTimeCellStyle.Brush = New MindFusion.Drawing.SolidBrush(Color.WhiteSmoke) 


Let me know if there is specific reason to use custom drawing.

Regards,
Meppy
  
Back to top
 
IP Logged
 
john6630
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 74
Joined: Sep 20th, 2010
Re: Custom draw to color specific cells
Reply #2 - Feb 15th, 2011 at 4:56am
Print Post  
Hi Meppy,
There are two problems using the work time. First is that the production day crosses calendar dates. For example, 7:30 AM until 1AM the next day. I can display the full set of time but the work time is limited to 0-24.

Secondly, you do not allow weekends to be work days. That is a severe limitation for an industrial application. We have lines that startup on Sunday, for example.

I would be interested in learning how to color part of the cell if the cell time is larger than the work end time (i.e. 60 min cell time and work ends on the half hour).

Thanks,
John
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Custom draw to color specific cells
Reply #3 - Feb 15th, 2011 at 7:06am
Print Post  
Aren't you using the version I posted here:

http://mindfusion.eu/Forum/YaBB.pl?board=calnet_disc;action=display;num=12969345...

It supports both cross-day working hours and display of working hours on weekends. We implemented those features specifically for you. Smiley

As for partial coloring of cells you should indeed use custom drawing. You have to manually calculate what portion of the cell to draw by relying on the cell's StartTime, EndTime and Bounds.

Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
john6630
Junior Member
**
Offline


I love YaBB 1G - SP1!

Posts: 74
Joined: Sep 20th, 2010
Re: Custom draw to color specific cells
Reply #4 - Feb 16th, 2011 at 3:38am
Print Post  
I tried the new version but still get the error that WorkTimeEndHour has to be between 0 and 24.

I am using VB.Net and I removed the reference to the two older DLL's and added a reference to the new ones and that is how I get this error.

I tried to delete the calendar component and re-add it, thinking it has something to do with the old one referencing the old DLL's and it would not allow me to add the calendar back. I got a VS error...I did not copy it all down.

What do I need to do to use this release? Do I have to create a new project from scratch?

John
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: Custom draw to color specific cells
Reply #5 - Feb 16th, 2011 at 7:05am
Print Post  
The new version supports WorkTimeEndHour up to 48. Somehow you still referenced the old version of the assemblies. Can you also post the error you got in VS?

Regards,
Meppy
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint