This is a migrated thread and some comments may be shown as answers.

Get the time for a click event position

2 Answers 44 Views
TimeLine
This is a migrated thread and some comments may be shown as answers.
Mathias
Top achievements
Rank 1
Mathias asked on 18 May 2012, 11:08 AM
Hi,

I need to allow the user to add timeline live events by clicking with the mouse somewhere in the timeline. Can anyone tell me how to get the time corresponding to a mouse click event?

Regards,
Mathias

2 Answers, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 23 May 2012, 08:20 AM
Hi Mathias,

In short, the timeline does not offer anything out of the box to help you in this respect. You can, however, use the following logic to calculate the time, corresponding to the mouse click:
  • Calculate the current visible period, that is timeline.VisiblePeriodEnd - timeline.VisiblePeriodStart.
  • Get the width of the timeline control.
  • Calculate the ticks-per-pixel value - just divide the visible period in ticks by the width of the control.
  • Check the X of the point, where the use clicked and multiply it by the ticks-per-pixel value - this should be the time value that you need.

Please note, that this method is not very accurate and in case you are visualizing a period of over a year, the day, minute, etc. might not be precise.

Kind regards,
Tsvetie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Johannes
Top achievements
Rank 1
answered on 26 Jun 2012, 05:44 PM
Don't forget to use the ActualWidth property if the width of your control can change during runtime.
Tags
TimeLine
Asked by
Mathias
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Johannes
Top achievements
Rank 1
Share this question
or