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 CortexZenUSA, Today, 12:53 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by CortexZenUSA, Today, 12:46 AM
          0 responses
          1 view
          0 likes
          Last Post CortexZenUSA  
          Started by usazencortex, Today, 12:43 AM
          0 responses
          5 views
          0 likes
          Last Post usazencortex  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          168 responses
          2,266 views
          0 likes
          Last Post sidlercom80  
          Started by Barry Milan, Yesterday, 10:35 PM
          3 responses
          13 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X