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 helpwanted, Today, 03:06 AM
    1 response
    12 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    9 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    5 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    242 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    387 views
    1 like
    Last Post Gavini
    by Gavini
     
    Working...
    X