Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X