Maximum width of text within VBA textbox control

Discussion in 'AutoCAD' started by Allen Johnson, Dec 6, 2004.

  1. Does anyone have a method to find the maximum width of text within a VBA
    multiline text box?
    I'd like something to find the longest line of text of a note such as:

    8" CONCRETE CAP SLAB
    REINFORCE W/ #5 @ 8" O.C. EA WAY
    ELEVATION TOP SLAB 108-0

    The only property I can find is the .CurX Property.
    VB has the .Textwidth method, but it doesn't appear to exist in VBA.

    The reason is I'd like to size the textbox control to be fairly
    representative of the maximum length of the longest line within the textbox
    control.
     
    Allen Johnson, Dec 6, 2004
    #1
  2. Allen Johnson

    Ed Jobe Guest

    I see now. How about setting AutoSize to True?
     
    Ed Jobe, Dec 6, 2004
    #2
  3. Good idea! Thanks.

    With txtNotes
    .AutoSize = True
    .Text = TextString
    tbw = .Width
    .AutoSize = False
    .Width = 1.2 * tbw
    .Left = (Me.Width - .Width) / 2
    .Height = 95
    End With
     
    Allen Johnson, Dec 6, 2004
    #3
  4. Allen Johnson

    Ed Jobe Guest

    You're welcome. Another FYI, might be to calulate it from the width of a
    char (in points), multiplied by the LEN of the widest string. Although I
    think you've got the easier way.
     
    Ed Jobe, Dec 6, 2004
    #4
  5. Allen Johnson

    AKS Guest

    Don't forget to resize your form to fit your resized textbox. Sooner or later you will be resizing other items and then you may run into the frustrating problem of your newly calculated resized objects not always updating to the resized dimension.
     
    AKS, Dec 6, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.