Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic make the ShowWorkTime line more visible (Read 6215 times)
fractal07
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Location: France
Joined: Mar 13th, 2017
make the ShowWorkTime line more visible
May 26th, 2017 at 5:28pm
Print Post  
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 | 228 Downloads )
ShowWorkTime.jpg
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: make the ShowWorkTime line more visible
Reply #1 - May 29th, 2017 at 8:00am
Print Post  
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
Select All
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);
			}
		}
	}; 


Let me know if this helps.

Regards,
Meppy
  
Back to top
 
IP Logged
 
fractal07
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Location: France
Joined: Mar 13th, 2017
Re: make the ShowWorkTime line more visible
Reply #2 - Jun 1st, 2017 at 7:03pm
Print Post  
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)
  
Back to top
 
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: make the ShowWorkTime line more visible
Reply #3 - Jun 2nd, 2017 at 9:51am
Print Post  
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
Select All
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);
		}
	}; 


Regards,
Meppy
  
Back to top
 
IP Logged
 
fractal07
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Location: France
Joined: Mar 13th, 2017
Re: make the ShowWorkTime line more visible
Reply #4 - Jun 20th, 2017 at 8:49am
Print Post  
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
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Online


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: make the ShowWorkTime line more visible
Reply #5 - Jun 21st, 2017 at 8:33am
Print Post  
Hi,

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

Code
Select All
c.TimetableSettings.StartTime = 60 * 8; // specified in minutes
 



This fixes it for me -

Code
Select All
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
  
Back to top
 
IP Logged
 
fractal07
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 28
Location: France
Joined: Mar 13th, 2017
Re: make the ShowWorkTime line more visible
Reply #6 - Jul 5th, 2017 at 9:03am
Print Post  
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 Wink
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Online


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: make the ShowWorkTime line more visible
Reply #7 - Jul 5th, 2017 at 1:43pm
Print Post  
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
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint