Author Topic: TextBox extents in .NET  (Read 2084 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
TextBox extents in .NET
« on: November 22, 2015, 10:53:15 AM »
I needed to know programmatically the width of various textstrings using various  Styles.
The Text is just strings, not the value of a database resident object.

Persistance paid off ....
There are several nice  methods in the Autodesk.AutoCAD.GraphicsInterface namespace

This is a tester to prove the concept :
I haven't idiot-proofed it yet, so don't take it to the bank without some testing.

Code - C#: [Select]
  1.         //================================================
  2.         [CommandMethod("TextExtentsTest2")]
  3.         static public void TextWidth() {
  4.             var ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
  5.             var ts = new Autodesk.AutoCAD.GraphicsInterface.TextStyle();
  6.             ts.FromTextStyleTableRecord("Standard");
  7.             ts.TextSize = 25;
  8.             ed.WriteMessage("AP " + ts.ExtentsBox("AP", true, false, null).MaxPoint.X);
  9.             ed.WriteMessage("\nAPPLE " + ts.ExtentsBox("APPLE", true, false, null).MaxPoint.X);
  10.             ed.WriteMessage("\nAPPLESAUCE " + ts.ExtentsBox("APPLESAUCE", true, false, null).MaxPoint.X);
  11.         }
  12.         //================================================
  13.  
« Last Edit: November 22, 2015, 11:53:24 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: TextBox extents in .NET
« Reply #1 on: November 23, 2015, 07:56:10 AM »
Thanks Kerry!  I've been doing this the hard way.  Didn't know about these methods in Autodesk.AutoCAD.GraphicsInterface.
Revit 2019, AMEP 2019 64bit Win 10

sybold

  • Newt
  • Posts: 62
Re: TextBox extents in .NET
« Reply #2 on: November 23, 2015, 01:54:52 PM »
oh wow, great find!