Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to fit string in rectangle in OnRender() method?

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

    How to fit string in rectangle in OnRender() method?

    Hello.

    Is there a way to render string, using max height and max width, instead of text size?


    There is a way to create TextLayout, and then measure height and width of string.
    I need to perform a reversed task: set height and width of exact string, and then get size to use it in DrawText() or DrawTextLayout();

    Is it possible?
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    Hello fx.practic,

    You are wanting to use the width and height of a rectangle and convert this to a font size (or use this to choose a font size)?

    I'm not aware of a SharpDX method that does this.

    I think you are going to have to create some custom math / algorithm to convert this.
    You might trying try using the length x width of rectangle to get the area, and then look at the width and height of the font from the text layout and see if there is a common ration at different sizes.

    I was looking at the WPF FontSizeConverter, but I'm not certain this will suit your purposes.


    This thread will remain open for any community members that may know of a method that exists for this that I am not aware of.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you, Chelsea.
      I will explore FontSizeConverter class and put results here.

      My current solution that I consider as ugly is to re-create TextLayout in a loop with smaller and smaller font size until it fit my rectangle.
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment

      Latest Posts

      Collapse

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