Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ResourceView: Drawing on a specific position on the timeline (Read 3044 times)
Achim
Junior Member
**
Offline


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
ResourceView: Drawing on a specific position on the timeline
Jul 2nd, 2012 at 12:58pm
Print Post  
Hi there,

I want to draw a symbol on an Item which works - in general - very fine using Custom Drawing events. But now I realized that the drawing coordinates are relative to the _visible_ part of the Item.

That means when the ResourceView shows five days for example, and the calendar item is ten days, i'm not able to draw a symbol on day two because when the timeline is scrolled the symbol stays relative to the visible area.

Is there any possibility to draw relative to the item's virtual origin?

Thanks in advance
Achim
  
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ResourceView: Drawing on a specific position on the timeline
Reply #1 - Jul 2nd, 2012 at 2:24pm
Print Post  
Hi,

There is no easy way to do this. It is possible, but it will require to perform some calculations manually. The following example draws (hopefully) a red mark at the second day after the item's start:

Code
Select All
DateTime from = calendar1.GetDateAt(e.Bounds.Left + (int)e.Graphics.Transform.OffsetX, e.Bounds.Top);
DateTime to = calendar1.GetDateAt(e.Bounds.Right + (int)e.Graphics.Transform.OffsetX, e.Bounds.Top);
DateTime mark = e.Item.StartTime.AddDays(2);
if (from <= mark && mark <= to)
{
	int distance = (int)(bounds.Width * ((double)mark.Ticks - from.Ticks) / (to.Ticks - from.Ticks));
	e.Graphics.DrawLine(Pens.Red, bounds.Left + distance, bounds.Top, bounds.Left + distance, bounds.Bottom);
} 


There is an ugly bit in the above code because the supplied drawing rectangle is not in Calendar coordinates and we need to translate it using the current graphics transformation.

I hope this helps.

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


MindFusion rocks!

Posts: 70
Location: Bayreuth, Germany
Joined: Jun 28th, 2012
Re: ResourceView: Drawing on a specific position on the timeline
Reply #2 - Jul 3rd, 2012 at 6:41am
Print Post  
Hi Meppy,

many thanks for that! I had not yet discovered the .Transform-Property. But tell me: why do think this is ugly? Ok, it would be more elegant, when the Calendar-Control could provide more information about the element being drawn. But this solution seems to be adequate.

Once again: thank you very much!

Achim
  
Back to top
WWW  
IP Logged
 
Meppy
God Member
*****
Offline


MindFusion support

Posts: 1783
Joined: Jul 20th, 2005
Re: ResourceView: Drawing on a specific position on the timeline
Reply #3 - Jul 3rd, 2012 at 7:16am
Print Post  
The ugly bit is that the bounding rectangle needs to be converted to client coordinates. This is not initially obvious nor is it documented and in most cases the user would not care. Smiley

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