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 mattbsea, Today, 05:44 PM
    0 responses
    4 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    31 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    2 views
    0 likes
    Last Post tkaboris  
    Started by GussJ, 03-04-2020, 03:11 PM
    16 responses
    3,282 views
    0 likes
    Last Post Leafcutter  
    Started by WHICKED, Today, 12:45 PM
    2 responses
    20 views
    0 likes
    Last Post WHICKED
    by WHICKED
     
    Working...
    X