Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Creating a Border around a Rectangle

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

    Creating a Border around a Rectangle

    Hi guys,

    With your help (and SharpDX's) I have created a rectangle and added some text to it. I now want to create a 2px border around the rectangle and I'm not really sure how to go about it.

    Here is what I have so far:

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {    
      //Let's create the rectangle first
      //implicitly recreate and dispose of brush on each render pass
      using (SharpDX.Direct2D1.SolidColorBrush dxBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.DodgerBlue))
      {
        RenderTarget.FillRectangle(new SharpDX.RectangleF((ChartPanel.X + 10), (ChartPanel.Y + 150), (ChartPanel.W - 687), (ChartPanel.H - 180)), dxBrush);
      }
    
      SharpDX.Vector2 startPointTitleBuy = new SharpDX.Vector2(ChartPanel.X + 18, ChartPanel.Y + 155);
      SharpDX.DirectWrite.TextFormat textFormatTitleBuy = new SharpDX.DirectWrite.TextFormat(Core.Globals.DirectWriteFactory, "Calibiri", SharpDX.DirectWrite.FontWeight.DemiBold, SharpDX.DirectWrite.FontStyle.Normal, 18);
      SharpDX.RectangleF rectangleFTitleBuy = new SharpDX.RectangleF(startPointTitleBuy.X, startPointTitleBuy.Y, ChartPanel.W, ChartPanel.H);
      SharpDX.Direct2D1.SolidColorBrush customDXTitleBuyBrush = new SharpDX.Direct2D1.SolidColorBrush(RenderTarget, SharpDX.Color.AliceBlue);
      RenderTarget.DrawText("My Cool Buy Title", textFormatTitleBuy, rectangleFTitleBuy, customDXTitleBuyBrush);
      textFormatTitleBuy.Dispose();
      customDXTitleBuyBrush.Dispose();
    Any ideas how I can do this?

    Thanks!

    #2
    Hello Bluebeep,

    Thanks for your inquiry.

    You could easily use RenderTarget.DrawRectangle() to draw a rectangle with 2px thick stroke width after you draw your FillRectangle and and the rectangle will be drawn over the filled rectangle.

    Publicly available documentation can be found below.



    You can also reference the SampleCustomRender indicator included with NinjaTrader at lines 177 and 180 where FillRectangle and DrawRectangle are used to create this effect.

    Let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Awesome thanks! Sample code is super useful!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by rexsole, Today, 08:39 AM
      0 responses
      4 views
      0 likes
      Last Post rexsole
      by rexsole
       
      Started by trilliantrader, Yesterday, 03:01 PM
      3 responses
      30 views
      0 likes
      Last Post NinjaTrader_Clayton  
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      4 responses
      26 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Brevo, Today, 01:45 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by rjbtrade1, 11-30-2023, 04:38 PM
      2 responses
      74 views
      0 likes
      Last Post DavidHP
      by DavidHP
       
      Working...
      X