Article ID: 197116
Article Last Modified on 5/12/2003
To maintain a constant horizontal size for the Label and allow for increasing or decreasing text, set the WordWrap and AutoSize properties to True.
If both AutoSize and WordWrap are set to True, text will wrap without increasing the size of the Label control, unless a single word is entered that is larger than the width of the Label. In that case, the AutoSize property takes priority and the width of the Label increases to accommodate the long word.
Option Explicit
Const LABEL_WIDTH = 2880
Private Sub Form_Load()
' Clear textbox initial value.
Text1.Text = ""
' Set both controls to the same initial width.
Text1.Width = LABEL_WIDTH
Label1.Width = LABEL_WIDTH
' Set colors for easy viewing.
Me.BackColor = vbRed
Text1.BackColor = vbGreen
Label1.BackColor = vbGreen
' Make sure Form is wide enough for Label to grow.
Me.Width = LABEL_WIDTH + Label1.Left + 1000
End Sub
Private Sub Text1_Change()
' Sync the two control's displays.
Label1.Caption = Text1.Text
' Check for change in label's width.
If Label1.Width <> LABEL_WIDTH Then
Debug.Print "Label Width: " & Label1.Width & _
vbTab & "TextBox Width: " & Text1.Width
End If
End Sub
Keywords: kbbug kbpending kbcode KB197116