Get the time for a click event position

3 posts, 0 answers
  1. Mathias
    Mathias avatar
    10 posts
    Member since:
    Aug 2011

    Posted 18 May 2012 Link to this post


    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?

  2. Tsvetie
    Tsvetie avatar
    1517 posts

    Posted 23 May 2012 Link to this post

    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,
    the Telerik team

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

  3. Johannes
    Johannes avatar
    13 posts
    Member since:
    Mar 2011

    Posted 26 Jun 2012 Link to this post

    Don't forget to use the ActualWidth property if the width of your control can change during runtime.
Back to Top