- Welcome, Guest. Please Login or Register
MindFusion  
  Version 2 of our Xamarin Calendar component adds Resource view and support for Universal Windows Platform. Now beta testing UWP version of Xamarin Diagram.  
  HomeHelpSearchLoginRegister   
     
     
   
 
Page Index Toggle Pages: 1 Send Topic Print  
make the ShowWorkTime line more visible
Read 421 times

fractal07   Offline
YaBB Newbies
*
Posts: 21
Gender: male
France
I Love MindFusion!


   
     
 
make the ShowWorkTime line more visible
May 26th, 2017 at 6: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 | 35 )
ShowWorkTime.jpg
 
IP Logged    
 
     

Meppy   Offline
YaBB Moderator
*****
Posts: 1771
Gender: male
MindFusion support


   
     
 
Re: make the ShowWorkTime line more visible
Reply #1 - May 29th, 2017 at 9: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);
			}
		}
	}; 


Let me know if this helps.

Regards,
Meppy
 
 
 
IP Logged    
 
     

fractal07   Offline
YaBB Newbies
*
Posts: 21
Gender: male
France
I Love MindFusion!


   
     
 
Re: make the ShowWorkTime line more visible
Reply #2 - Jun 1st, 2017 at 8: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)
 
 
 
IP Logged    
 
     

Meppy   Offline
YaBB Moderator
*****
Posts: 1771
Gender: male
MindFusion support


   
     
 
Re: make the ShowWorkTime line more visible
Reply #3 - Jun 2nd, 2017 at 10: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);
		}
	}; 


Regards,
Meppy
 
 
 
IP Logged    
 
     

fractal07   Offline
YaBB Newbies
*
Posts: 21
Gender: male
France
I Love MindFusion!


   
     
 
Re: make the ShowWorkTime line more visible
Reply #4 - Jun 20th, 2017 at 9: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
 
 
 
IP Logged    
 
     

Slavcho   Online
God Member
*****
Posts: 1245
Gender: male
tech.support


   
     
 
Re: make the ShowWorkTime line more visible
Reply #5 - Jun 21st, 2017 at 9: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
 



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
 
 
 
IP Logged    
 
     

fractal07   Offline
YaBB Newbies
*
Posts: 21
Gender: male
France
I Love MindFusion!


   
     
 
Re: make the ShowWorkTime line more visible
Reply #6 - Jul 5th, 2017 at 10: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 Wink
 
 
 
IP Logged    
 
     

Slavcho   Online
God Member
*****
Posts: 1245
Gender: male
tech.support


   
     
 
Re: make the ShowWorkTime line more visible
Reply #7 - Jul 5th, 2017 at 2: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
 
 
 
IP Logged    
 
     
Page Index Toggle Pages: 1 Send Topic Print