• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    https://docs.microsoft.com/en-us/dot...ew=netcore-3.1

    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 Bsmckm, Today, 02:02 PM
      0 responses
      8 views
      0 likes
      Last Post Bsmckm
      by Bsmckm
       
      Started by markyb0y, Today, 01:55 PM
      0 responses
      4 views
      0 likes
      Last Post markyb0y  
      Started by SlickRick, Today, 11:07 AM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Started by JTizz, Today, 12:17 PM
      0 responses
      7 views
      0 likes
      Last Post JTizz
      by JTizz
       
      Started by Tradarr, Today, 09:25 AM
      1 response
      17 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Working...
      X