Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to get 2 mouse clicks - not double click

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

    How to get 2 mouse clicks - not double click

    HI
    I am trying to get 2 sets of co ordinates via OnMouseDown using a click counter
    Code:
            #region mouse    
            public void MiddleMouseButtonExample_MouseDown(object sender, MouseButtonEventArgs e)
            {
                if(ClickCounter == 0)
                {
                if (e.MiddleButton == MouseButtonState.Pressed)
                {
                    clickPoint.X = ChartingExtensions.ConvertToHorizontalPixels(e.GetPosition(ChartPanel as IInputElement).X, ChartControl.PresentationSource);
                /   clickPoint.Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPosition(ChartPanel as IInputElement).Y, ChartControl.PresentationSource);
                    ClickCounter += 1;
                }
                }///end ClickCounter = 0
    
                if(ClickCounter == 1)
                {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    clickPoint2.X = ChartingExtensions.ConvertToHorizontalPixels(e.GetPosition(ChartPanel as IInputElement).X, ChartControl.PresentationSource);
                    clickPoint2.Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPosition(ChartPanel as IInputElement).Y, ChartControl.PresentationSource);
    
                    if (clickPoint2.Y > 0)
                    {
                        clickSet = true;
                        barIdx2 = -1;
                        barIdx = -1;
                    }
                    // trigger the chart invalidate so that the render loop starts even if there is no data being received
                    ChartControl.InvalidateVisual();
                    e.Handled = true;
                    ClickCounter = 0;
                    //Print(clickPoint.X);
                    //Print(clickPoint2.X);
                }
                }///end ClickCounter = 1;
    
    
            }
            #endregion
    ​
    However I want the chart to 'wait'for the second click - currently it just goes straight to the second mouse method, giving me the exact same co ordinates
    If I change the mouse button eg leftbutton == MouseButtonState,Pressed first then middle button == MouseButtonState.Pressed - it all works fine - but I just want to click the left button, move the mouse and click the left button again, and then the rest of my logic can be run.
    Can anyone point me in the right direction?
    Last edited by Mindset; 09-18-2022, 08:18 PM. Reason: Correct code

    #2
    Hello Mindset,

    Your second condition set will always be true if the first condition set is true. You are setting the value to 1 then checking if its 1.

    Perhaps you were meaning to use an else if, so both conditions cannot be true?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea.
      But what I am trying to achieve is 2 left mouse clicks with different co ordinates - and if use else if of course I only end up with one.
      I thought that the counter and the ismousebuttonpressed conditions would prevent the method from completing until I had clicked the second time?

      Comment


        #4
        Hello Mindset,

        It would not. You are setting the Counter to 1 and then immediately below checking if its 1. It will always be 1 because you set it 1.
        Meaning it happens immediately, not the next time the mouse is clicked.
        You are wanting to wait until the mouse is clicked a second time right?
        So either return immediately after setting the counter to 1, or use an else if so that when the value is set to 1, the second condition is not immediately evaluated until the mouse is clicked again.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          LOl Can't believe it was that simple. thanks Chelsea_B

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by andrewtrades, Today, 04:57 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          3 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          436 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          7 views
          0 likes
          Last Post FAQtrader  
          Started by rocketman7, Today, 09:41 AM
          5 responses
          19 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X