Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

I had it working and now it doesn't!

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

    I had it working and now it doesn't!

    Code:
    SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode;
    RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.Aliased;
    
    blockstring.Append(String.Format("({0})", "Hello"));
    
    SharpDX.Direct2D1.Brush textBrushDx;
    Brush textBrush = ChartControl.Properties.AxisPen.Brush;
    
    textBrushDx = textBrush.ToDxBrush(RenderTarget);
    
    
    SharpDX.DirectWrite.TextFormat textFormat1 = subFont.ToDirectWriteTextFormat();
    // blockstring.Clear();
    SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory,
    blockstring.ToString(), textFormat1, ChartPanel.X + ChartPanel.W,
    textFormat1.FontSize);//this binds it to the ChartPanel space ONLY
    
    SharpDX.Vector2 textPoint = new SharpDX.Vector2(ChartPanel.X-30 + (ChartPanel.W/2),ChartPanel.Y );
    
    RenderTarget.DrawTextLayout(textPoint, textLayout1, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
    
    
    textLayout1.Dispose();
    textBrushDx.Dispose();
    textFormat1.Dispose();
    RenderTarget.AntialiasMode = oldAntialiasMode;
    Spent 2 hours on this - had it working and now just can't get it to display - please tell me where I am going wrong.

    thanks
    Last edited by Mindset; 10-09-2020, 03:19 AM. Reason: Found the answer. I had a condition above it that was incorrect

    #2
    Hello Mindset,

    Thanks for your post.

    The script may not have a string in blockstring that would be visible, or the brush that is being used is transparent.

    You can hard code a brush and a string in your code to verify that the code is working properly when there is a definite string and brush given.

    For example, you could check your code with a hard coded brush and string as follows:

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
        SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode;
        RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.Aliased;
    
        SharpDX.Direct2D1.Brush textBrushDx;
        System.Windows.Media.Brush textBrush = Brushes.Orange;
    
        textBrushDx = textBrush.ToDxBrush(RenderTarget);
    
    
        SharpDX.DirectWrite.TextFormat textFormat1 = ChartControl.Properties.LabelFont.ToDirectWriteTex tFormat();
    
        SharpDX.DirectWrite.TextLayout textLayout1 = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory,
        "Test", textFormat1, ChartPanel.X + ChartPanel.W,
        textFormat1.FontSize);//this binds it to the ChartPanel space ONLY
    
        SharpDX.Vector2 textPoint = new SharpDX.Vector2(ChartPanel.X-30 + (ChartPanel.W/2),ChartPanel.Y );
    
        RenderTarget.DrawTextLayout(textPoint, textLayout1, textBrushDx, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
    
    
        textLayout1.Dispose();
        textBrushDx.Dispose();
        textFormat1.Dispose();
        RenderTarget.AntialiasMode = oldAntialiasMode;
    }
    We look forward to assisting.

    Comment


      #3
      Thanks Jim
      I am trying to get different texts with different colours.
      Where am I going wrong here - looks simple enough?

      Code:
      if (ChartBars == null)
      return;
      int txtHeight = (int)subFont.TextFormatHeight; // (int)graphics.MeasureString("X", txtFont).Heig
      
      //Anti alias lines
      //Append to stringbuilder
      // Declare BrushDx
      //place text Brush to DXBrush
      //textlayout declaration
      //Vector 2 text point
      //Dispose
      
      ChartPanel panel = chartControl.ChartPanels[chartScale.PanelIndex];
      SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode;
      RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.Aliased;
      
      
      
      SharpDX.Direct2D1.Brush textBrushDxW;
      SharpDX.Direct2D1.Brush textBrushDxG;
      Brush textBrush = Brushes.White;//Brushes.AliceBlue;//ChartControl.Properties.AxisPen.Brush;
      Brush textBrushGreen = Brushes.Chartreuse;
      // areaBrushDx = areaBrush.ToDxBrush(RenderTarget);
      textBrushDxW = textBrush.ToDxBrush(RenderTarget);
      textBrushDxG = textBrush.ToDxBrush(RenderTarget);
      
      
      SharpDX.DirectWrite.TextFormat textFormat1 = subFont.ToDirectWriteTextFormat();
      
      ///White
      SharpDX.DirectWrite.TextLayout textLayoutwhite = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory,
      whitestring.ToString(), textFormat1, ChartPanel.X + ChartPanel.W,
      textFormat1.FontSize);//this binds it to the ChartPanel space ONLY
      
      ///Green
      SharpDX.DirectWrite.TextLayout textLayoutgreen = new SharpDX.DirectWrite.TextLayout(NinjaTrader.Core.Gl obals.DirectWriteFactory,
      greenstring.ToString(), textFormat1, ChartPanel.X + ChartPanel.W,
      textFormat1.FontSize);//this binds it to the ChartPanel space ONLY
      
      
      SharpDX.Vector2 textPoint = new SharpDX.Vector2(ChartPanel.X-30 + (ChartPanel.W/2),ChartPanel.Y );
      
      RenderTarget.DrawTextLayout(textPoint, textLayoutwhite, textBrushDxW, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
      SharpDX.Vector2 textPoint2 = new SharpDX.Vector2(ChartPanel.X-30 + (ChartPanel.W/2),ChartPanel.Y+txtHeight );
      RenderTarget.DrawTextLayout(textPoint2, textLayoutgreen, textBrushDxG, SharpDX.Direct2D1.DrawTextOptions.NoSnap);
      
      
      textLayoutwhite.Dispose();
      textLayoutgreen.Dispose();
      textBrushDxW.Dispose();
      textBrushDxG.Dispose();
      
      //areaBrushDx.Dispose();
      textFormat1.Dispose();
      RenderTarget.AntialiasMode = oldAntialiasMode;

      Comment


        #4
        Oh I forgot to change the Brush - Jeez!!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        627 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        359 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        562 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X