-
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.
-
Hello btz3d,
Try this source:
MsgBox Len(Text1.Text)
Michelle.
-
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
-
This is independent of font. Except it seems to get it wrong, hence the + 90.
Code:
Text1.Width = TextWidth(Text1.Text) + 90
-
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
-
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.