Microsoft KB Archive/197116

= BUG: Label Width Changes with WordWrap and AutoSize Set to True =

Article ID: 197116

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Control Creation Edition
 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition

-



This article was previously published under Q197116



SYMPTOMS
If you set the Caption property of a Label control when the label's WordWrap and AutoSize properties are set to True, Visual Basic slightly changes the width of the label instead of wrapping the label's caption.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.



MORE INFORMATION
According to Visual Basic Help, the horizontal size of a label should not change when the WordWrap and AutoSize properties are both set to True, unless the label's caption consists of a single word that is larger than the width of the Label.

The following are excerpts from the Visual Basic 6.0 WordWrap Help topic:

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.

Steps to Reproduce Behavior
 Create a new Standard EXE project. Form1 is created by default. Add a TextBox and a Label control to Form1. Set the MultiLine property of the TextBox control to True. Set the BorderStyle property of the TextBox control to None. Set the AutoSize and WordWrap properties of the Label control to True.  Paste the following code into Form1: 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 </li> Run the project.</li></ol>

RESULT: Begin typing some text into the TextBox until the debug window shows a change in the label's width. The actual amount of typing you must do to see this behavior can vary from system to system. To consistently cause this behavior, type some text up to the end of the first line and then hit the space bar several times, or just enter spaces.

Keywords: kbbug kbpending kbcode KB197116

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.