I have this text box which display multiple lines from a text file on my form, I want the box resize as the form gets resize without cutting any text in it, the textbox display multiple line of text and i want a textwrapping feature if it possible on the text box when the form gets resize, is there anyway i can do this.


5 Years
Discussion Span
Last Post by Deepak Shitole

You need to hook up the height and width property of the text box with that of the containing form. Handle that in the form_resize event.


Thanks, but could you please give a coded example, i tried so many times but could not quite work it out. Well, my form has a list box and a RTB which i need to resize and the text inside the RTB to be wrap as the form gets resize without cutting the boxes.

When i gets resize it gives runtime error '380' Invalid property value, would be very grateful if you could help me on this.



When doing resizing in VB6 you need to be careful to include an On Error
statement. The following example illustrates how to resize a text box to
correspond with the size of the form as it resizes. You need to do similar
coding to deal with height. The principles shown here can be applied to other

But you need to establish original values and save them for future calculations
within the resize event of the form.

Option Explicit
Private lngOrigTxtWidth As Long
Private lngOrigFormWidth As Long
Private Sub Form_Load()
    lngOrigTxtWidth = Text1.Width
    lngOrigFormWidth = Form1.Width
End Sub

Private Sub Form_Resize()
    On Error GoTo Resize_Error
    Dim lngNewWidth As Long
    ' use ratios to calculate a new value.
    ' lngOrigTxtWidth / lngOrigFormWidth = Unknown / me.ScaleWidth
    ' Unknown = me.scalewidth * (lngOrigTxtWidth/lngOrigFormWidth)
    lngNewWidth = ScaleWidth * (lngOrigTxtWidth / lngOrigFormWidth)
    Text1.Width = lngNewWidth
    Exit Sub
    Debug.Print Err.Description
End Sub

Sometimes when resizing you come up with invalid values that don't make sense:
i.e., division by zero, etc.

Edited by hkdani: n/a


Dear Friend,

In my example origional left position of text is 0
and i am maintaining the width of text box as per the form's size.
using the following line of code.

Private Sub Form_Resize()
    Text1.Width = Me.Width - 200
End Sub

Private Sub Form_Load()
    Text1.Width = Me.Width - 200
End Sub

In case of any issue please feel free to ask me

Edited by Ezzaral: Added code tags. Please use them to format any code that you post. Also snipped contact info.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.