Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Detecting mouse clicks on drawing objects

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

    Detecting mouse clicks on drawing objects

    Hi,

    I do have a way to do this, but I was wondering if there a better, simpler way to do this?
    Basically I wish to turn a FixedText into a switch button. To do that I need mouseclick event, then a way to check if the cursor has clicked on the drawing object.
    alertStatusSwitch flips between true/false

    The magic happens here:
    Code:
    Cursor tfCursor = tfAlertStatus.GetCursor(this.ChartControl, this.ChartPanel, this.ChartPanel.Scales[0], cursorPoint);
    If the cursor clicked on the drawing object, then it will return a cursor, otherwise it returns NULL.
    Since the indicator creates this TextFixed drawing object, is there a better way to detect clicks on this drawing object?

    Thanks in advance.


    Here is my code:

    Code:
    protected override void OnStateChange()
    {
        if (State == State.SetDefaults)
        {
            // OMMITTED //
        }
        else if (State == State.Configure)
        {
            alertStatusSwitch = true;
            tfAlertStatus = Draw.TextFixed(// OMMITTED //);
            tfAlertStatus.YPixelOffset = ChartAlertStatusYPixelOffset;
            if (ChartControl != null) {
                ChartControl.MouseLeftButtonUp += MouseClicked;
            }
        }
        else if (State == State.Terminated) {
            if (ChartControl != null) {
                ChartControl.MouseLeftButtonUp -= MouseClicked;
            }
        }
    }
    
    protected void MouseClicked(object sender, MouseButtonEventArgs e)
    {
        Point cursorPoint = this.ChartControl.MouseDownPoint;
        Cursor tfCursor = tfAlertStatus.GetCursor(this.ChartControl, this.ChartPanel, this.ChartPanel.Scales[0], cursorPoint);
        if (tfCursor != null) {
            if (alertStatusSwitch) {
                tfAlertStatus = Draw.TextFixed(// OMMITTED //);
                tfAlertStatus.YPixelOffset = ChartAlertStatusYPixelOffset;
                alertStatusSwitch = false;
                ForceRefresh();
            } else {
                tfAlertStatus = Draw.TextFixed(// OMMITTED //);
                tfAlertStatus.YPixelOffset = ChartAlertStatusYPixelOffset;
                alertStatusSwitch = true;
                ForceRefresh();
            }
        }
    }

    #2
    Hello Gorkhaan,

    Thanks for your post.

    I think the easy thing to do would be to add a button to the chart instead. Drawing Objects are also intended to be moved when they are selected (TextFixed is an exception,) so attempting to wire into the Drawing Tools Mouse events wouldn't be advised.

    You can see an example that implements buttons below. If that is not a more elegant solution for you, then you may wish to proceed with what you have.



    The link above is publicly available.

    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.


    We look forward to assisting.

    Comment


      #3
      Hi Jim,

      Thanks a lot I'll look into it.

      G.

      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