Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically resize and position text boxes according to contents 3

Status
Not open for further replies.

casperthedog

Instructor
Jan 29, 2002
20
0
0
NZ
I have a form containing text boxes where each text box contains a word from a sentence (each word being the contents of a field in a database). How can I have the text boxes automatically resize and position themselves a few pixels to the right of the previous text box, so that when the borders are removed it looks like a normal typed sentence:

I want it to look like this...

I don't want it to look like this...
 
Try passing the values to a global sub

Public Sub AddToSize(ThisText As TextBox)

ThisText.Width = ThisText.Width + 75

End Sub

Private Sub Text1_Change()
AddToSize Text1
End Sub
 
The re-sizing of the boxes would work only to keep the size of the box small, but the positioning might still make it look messy such as

[This] [is] [The] [Text]

What you can do is this. Set the boxes to AutoSize, this will make them so that they will only be as big as the word is. Then put in this code into each text box.

Sub Text1_Change()
Text2.Left = Text1.Left + Text1.Width 'You may have to add another + ### Just incase they are too close

End Sub Craig, mailto:sander@cogeco.ca
"Procrastination is the art of keeping up with yesterday."
I hope my post was helpful!!!
 
Textboxes do not have an AutoSize property. That is why I suggested Labels. As to the postioning, I leave that as simple exercise. You really only need one Label with AutoSize=True and Alignment=0 to do the sizing. The textboxes, if needed, can be resized from the label properties. I would include a trailing space in the Label.Caption. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Very good suggestion. You could combine the 2 posts into 1 to get something to look really good.

So get the size of the Text box from a label, then poistion it according to the position of the last text box plus it's width.

Craig, mailto:sander@cogeco.ca
"Procrastination is the art of keeping up with yesterday."
I hope my post was helpful!!!
 
Thank you all for your help. In the end I used labels to display the data from the fields with Autosize set to True and the position based on the previous laebels left position plus its width plus a few more pixels for spacing.

I also created a subroutine to carry out this positioning with each record change because it would originally only work when the form first opened. After that it seemed to jumble the left values up a bit (I think it was using the original left values from the form design).

But it's sorted now - with the help of you all.

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top