• 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 GTBrooks, Today, 02:44 PM
      0 responses
      2 views
      0 likes
      Last Post GTBrooks  
      Started by GLFX005, Today, 12:22 PM
      3 responses
      36 views
      0 likes
      Last Post GLFX005
      by GLFX005
       
      Started by AspenHiker, Today, 08:37 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by MartinT, Yesterday, 01:12 PM
      3 responses
      15 views
      0 likes
      Last Post MartinT
      by MartinT
       
      Started by caveat_lector, Today, 11:58 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Heath  
      Working...
      X