• 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 sandman, Today, 05:47 AM
      0 responses
      0 views
      0 likes
      Last Post sandman
      by sandman
       
      Started by sidviciousX, Yesterday, 07:24 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_EricB  
      Started by cls71, Today, 04:31 AM
      0 responses
      2 views
      0 likes
      Last Post cls71
      by cls71
       
      Started by KSTrader, Today, 12:45 AM
      0 responses
      3 views
      0 likes
      Last Post KSTrader  
      Started by Lklforex, Yesterday, 08:48 PM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Working...
      X