The MindFusion Forums
Scheduling and Gantt Components >> Windows Forms >> make the ShowWorkTime line more visible
https://mindfusion.eu/Forum/YaBB.pl?num=1495819731

Message started by fractal07 on May 26th, 2017 at 5:28pm

Title: make the ShowWorkTime line more visible
Post by fractal07 on May 26th, 2017 at 5:28pm
Hello,

Using the 2017.R1 version of WinForms.Scheduling, I'm looking for a way to increase the visibility of the Timeline displayed by ShowWorkTime.
I have many resources (= many columns) and I would display a continuous line to show the current time... not only in the left-column.
Does someone have an idea how to do it?


ShowWorkTime.jpg ( 88 KB | 234 Downloads )

Title: Re: make the ShowWorkTime line more visible
Post by Meppy on May 29th, 2017 at 8:00am
Hi,

You can use custom drawing to achieve this. Set Calendar.CustomDraw to CustomDrawElements.TimetableCell | CustomDrawElements.TimetableTimelineCell, then handle the Calendar.Draw event and perform the necessary calculations. Here is some sample code that can get you started:

[code]c.CustomDraw = CustomDrawElements.TimetableCell | CustomDrawElements.TimetableTimelineCell;
c.Draw += (s, e) =>
     {
           if (e.Element == CustomDrawElements.TimetableCell)
           {
                 if (e.Date + e.StartTime <= DateTime.Now && DateTime.Now <= e.Date + e.EndTime)
                 {
                       long ticks = DateTime.Now.Ticks - (e.Date + e.StartTime).Ticks;
                       long total = (e.EndTime - e.StartTime).Ticks;
                       var h = e.Bounds.Height * ticks / total;
                       using (var pen = new Pen(Color.Red, 4))
                             e.Graphics.DrawLine(pen, e.Bounds.X, e.Bounds.Y + h, e.Bounds.Right, e.Bounds.Y + h);
                 }
           }
           if (e.Element == CustomDrawElements.TimetableTimelineCell)
           {
                 if (e.StartTime <= DateTime.Now.TimeOfDay && DateTime.Now.TimeOfDay <= e.EndTime)
                 {
                       long ticks = DateTime.Now.TimeOfDay.Ticks - (e.Date + e.StartTime).Ticks;
                       long total = (e.EndTime - e.StartTime).Ticks;
                       var h = e.Bounds.Height * ticks / total;
                       using (var pen = new Pen(Color.Red, 4))
                             e.Graphics.DrawLine(pen, e.Bounds.X, e.Bounds.Y + h, e.Bounds.Right, e.Bounds.Y + h);
                 }
           }
     };[/code]
Let me know if this helps.

Regards,
Meppy

Title: Re: make the ShowWorkTime line more visible
Post by fractal07 on Jun 1st, 2017 at 7:03pm
Hi, Thank you for your help, Meppy!
The code suggested is almost perfect, I already modify it, but is there a way to bring the line to the very foreground? Doing this, the line will be displayed over the appointments, not under (we have too many appointments and the line is under them)

Title: Re: make the ShowWorkTime line more visible
Post by Meppy on Jun 2nd, 2017 at 9:51am
Hi,

You can draw on top of everything by handling the Calendar.Paint event and manually calculate the position of the current time. Use the following code as a reference:

[code]c.Paint += (s, e) =>
     {
           var bounds = c.GetElementBounds(CalendarElement.TimetableDayHeader, 0);
           var firstVisibleTime = new TimeSpan(c.VScrollPos * c.TimetableSettings.CellTime.Ticks);
           if (DateTime.Now.TimeOfDay > firstVisibleTime)
           {
                 float dcell = (float)(DateTime.Now.TimeOfDay.Ticks - firstVisibleTime.Ticks) / c.TimetableSettings.CellTime.Ticks;
                 var y = bounds.Bottom + dcell * c.TimetableSettings.CellSize;
                 using (var pen = new Pen(Color.Red, 4))
                       e.Graphics.DrawLine(pen, 0, y, Width, y);
           }
     };[/code]
Regards,
Meppy

Title: Re: make the ShowWorkTime line more visible
Post by fractal07 on Jun 20th, 2017 at 8:49am
Hi Meppy,

Thank you for your last code, I tried to adapt it but I do not understand how you calculate the firstVisibleTime, why use VScrollPos?
By the way, the timeline drawn is wrong, the line is displayed with about 8 hours more and I have far less properties using PaintEventArgs...
Please, could you shortly explain your code? The goal is to show le TimeLine (ok) over the tasks/appointments drawn (not ok).

Regards

Title: Re: make the ShowWorkTime line more visible
Post by Slavcho on Jun 21st, 2017 at 8:33am
Hi,

Above Paint handler will draw the line 8-hours off if you've changed timetable's StartTime to 8 hours -


Code (]
c.TimetableSettings.StartTime = 60 * 8; // specified in minutes
[/code):



This fixes it for me -

[code]
var firstVisibleTime =
     new TimeSpan(c.VScrollPos * c.TimetableSettings.CellTime.Ticks) +
     TimeSpan.FromMinutes(c.TimetableSettings.StartTime);


The Paint event is derived from base Control class and does not provide any calendar -specific arguments, that's why the handler has to calculate line's coordinates from current scroll position and various TimetableSettings properties.

Regards,
Slavcho
Mindfusion

Title: Re: make the ShowWorkTime line more visible
Post by fractal07 on Jul 5th, 2017 at 9:03am
Hi Slavcho,
Thank you for your help. I updated in our project and I still have a gap (25 min) between the native timeline of the calendar and this new one... but I tried  with a very new project using only a MindFusion scheduling and it works fine ;-)

Title: Re: make the ShowWorkTime line more visible
Post by Slavcho on Jul 5th, 2017 at 1:43pm
Hi, Could be some sub-header size we'll need to offset the line by. Try passing a different CalendarElement to GetElementBounds depending on what's displayed as last header by your main app.

Regards,
Slavcho

The MindFusion Forums » Powered by YaBB 2.6.11!
YaBB Forum Software © 2000-2024. All Rights Reserved.