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 Hwop38, 05-04-2026, 07:02 PM
    0 responses
    135 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    292 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    238 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    332 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    171 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X