Results 1 to 6 of 6

Thread: Text Box Adjustments

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Posts
    9

    Question

    What is simple code for adjusting a textbox's appearence to the length of the text enter? For example, if the person enters the name, Joe, I want the textbox to adjust its sixe to three characters. If the person's name is Alexander, I wnat the textbox to adjust its length to 9 characters.

  2. #2
    Hyperactive Member
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    455
    Hello btz3d,

    Try this source:

    MsgBox Len(Text1.Text)


    Michelle.

  3. #3
    Fanatic Member Ianpbaker's Avatar
    Join Date
    Mar 2000
    Location
    Hastings
    Posts
    696

    Talking

    In vb it is roughly 90 pixels per character for width attribute of text boxes (Providing it is the default font and size) so you could do the following to solve your problem

    Code:
    Private Sub Text1_Change()
        Text1.Width = Len(Text1) * 90
    End Sub
    This Harshly does what you ask for

    Hope this helps

    Ian
    Yeah, well I'm gonna build my own lunar space lander! With blackjack aaaaannd Hookers! Actually, forget the space lander, and the blackjack. Ahhhh forget the whole thing!

  4. #4
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    This is independent of font. Except it seems to get it wrong, hence the + 90.

    Code:
    Text1.Width = TextWidth(Text1.Text) + 90
    Iain, thats with an i by the way!

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    try this out for size

    Won't work in text change as noted above
    Make your font and measure work togeather.

    Try this out..

    Private Sub Text1_GotFocus()
    Text1.Text = ""
    Text1.Font = "New Roman"
    Text1.FontSize = "10"
    Text1.Width = 2000

    End Sub

    Private Sub Text1_LostFocus()
    Dim myText
    myText = Trim(Text1.Text)
    Text1.Width = Len(myText) * 80
    Text1.SelStart = 0
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Textwidth is a property of a picturebox or form, in this case the omitted Me keyword which should be the form within which it is used. It returns the text width of text used with the forms font so put the forms font to the textbox font first.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width