Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnMouseMove. Local Cursor is not refreshed

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

    OnMouseMove. Local Cursor is not refreshed

    Hello,

    this is a script that displays the coordinates of the mouse. As the mouse moves, the text is refreshed with new coordinates. It works fine.

    The problem arises if I change the type of cursor to Local (crosshair). Then the cursor does not move, it stays fixed (have to click on the ChartPanel for the cursor is refreshed) However, coordinates are painted and updated properly.

    Best Regards

    Code:
    public class MouseMove : Indicator
    	{
    		private Point mousePosition;
    		
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description					= @"Enter the description for your new custom Indicator here.";
    				Name						= "MouseMove";
    				Calculate					= Calculate.OnBarClose;
    				IsOverlay					= true;
    				DisplayInDataBox			= true;
    				DrawOnPricePanel			= true;
    				DrawHorizontalGridLines		= true;
    				DrawVerticalGridLines		= true;
    				PaintPriceMarkers			= true;
    				ScaleJustification			= NinjaTrader.Gui.Chart.ScaleJustification.Right;
    				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    				//See Help Guide for additional information.
    				IsSuspendedWhileInactive	= true;
    			}
    			else if (State == State.DataLoaded)
    			{
    				if( this.ChartPanel != null )
    					this.ChartPanel.MouseMove += new MouseEventHandler(this.OnMouseMove);
    			}
    			else if ( State == State.Terminated )
    			{
    				if( this.ChartPanel != null )
    					this.ChartPanel.MouseMove -= new MouseEventHandler(this.OnMouseMove);
    			}
    		}
    
    		internal void OnMouseMove(object sender, MouseEventArgs e)
        	        {
    			this.mousePosition = e.GetPosition( this.ChartPanel );
    			
    			this.ChartControl.InvalidateVisual();
    			
    			e.Handled = true;
    		}
    		
    		protected override void OnBarUpdate()
    		{
    		}
    		
    		protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    		{
    			base.OnRender(chartControl, chartScale);
    			
    			System.Windows.Media.Brush textBrush = Brushes.RoyalBlue;
    			SharpDX.Direct2D1.Brush textBrushDX = textBrush.ToDxBrush(RenderTarget);
    			SharpDX.RectangleF rectangleF = new SharpDX.RectangleF( 10.0F, 20.0F, 500.0F, 100.0F );
    			SharpDX.DirectWrite.TextFormat textFormat = new SharpDX.DirectWrite.TextFormat(Core.Globals.DirectWriteFactory, "Arial", SharpDX.DirectWrite.FontWeight.ExtraBold, 
    				SharpDX.DirectWrite.FontStyle.Normal, SharpDX.DirectWrite.FontStretch.Normal, 15.0F ); 
    			//{ TextAlignment = SharpDX.DirectWrite.TextAlignment.Leading, WordWrapping = WordWrapping.NoWrap };
    
    			String text = "Mouse: (" + this.mousePosition.X.ToString() + " , " + this.mousePosition.Y.ToString() + " )" + Environment.NewLine;
    			
    			RenderTarget.DrawText( text, textFormat, rectangleF, textBrushDX);
    		}
    	}

    #2
    Hello cls71,

    If you comment out e.Handled = true; in your handler, it should work fine.
    ArtSenior Software Developer

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    669 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    378 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    111 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    575 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    580 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X