• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to convert mouse point to chart point

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    How to convert mouse point to chart point

    What is the procedure for converting the mouse location to a proper chart location? I want to be able to tell when the mouse is over a drawing object in the chart.

    I have tried the following:

    Code:
    ChartControl.MouseMove += ChartMouseMove;
    
    private void ChartMouseMove(object s, MouseEventArgs e)
    {
        var pos = e.GetPosition(ChartControl);
        // or var pos = e.GetPosition(ChartControl.OwnerChart);
    }
    The resulting point is not corresponding with drawing objects on the chart.

    Thanks.

    #2
    Hello wbennettjr,

    You can convert a price to a y value and time/barSlot to x and vice versa.

    Below is a link to an example.
    http://ninjatrader.com/support/forum...684#post499684

    http://ninjatrader.com/support/helpG...ntalpixels.htm
    http://ninjatrader.com/support/helpG...calpixels2.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea,

      Based on the links you provided, I changed the code to

      Code:
      ChartControl.MouseMove += ChartMouseMove;
      
      private void ChartMouseMove(object s, MouseEventArgs e)
      {
          var pos = e.GetPosition(ChartControl);
          pos.X = ChartingExtensions.ConvertToHorizontalPixels(pos.X, 
      ChartControl.PresentationSource);
          pos.Y = ChartingExtensions.ConvertToVerticalPixels(pos.Y, ChartControl.PresentationSource);
      }
      Works like a charm!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by supermht, Today, 07:59 PM
      0 responses
      2 views
      0 likes
      Last Post supermht  
      Started by mohdhm, Today, 05:13 PM
      1 response
      12 views
      0 likes
      Last Post nkhoi
      by nkhoi
       
      Started by 3lliot, Today, 05:55 PM
      0 responses
      2 views
      0 likes
      Last Post 3lliot
      by 3lliot
       
      Started by Fargo, Today, 04:57 PM
      0 responses
      11 views
      0 likes
      Last Post Fargo
      by Fargo
       
      Started by Johnny Santiago, Today, 03:57 PM
      0 responses
      10 views
      0 likes
      Last Post Johnny Santiago  
      Working...
      X