List Boxes Can Shrink When a Form Is Saved in Text Format (141940)



The information in this article applies to:

  • Microsoft Visual Basic Standard Edition for Windows 3.0
  • Microsoft Visual Basic Professional Edition for Windows 3.0

This article was previously published under Q141940

SYMPTOMS

Every time a project is run, a list box appears with a smaller height than when the form was previously saved. The behavior seems to depend on whether the form was saved in text format or binary, and the font used in the list box. The list box does not grow any smaller once an executable is made.

The same problem described above can also occur for a file list box.

STATUS

This problem was fixed in both 16- and 32-bit versions of Visual Basic 4.0 (where all forms are saved only in a text format).

MORE INFORMATION

The problem described above occurs under certain circumstances. First, the height of the list box shrinks after the form has been saved in text format. (To save a form in text format, highlight the form in the project window and on the File menu, click Save File As, with the Save As Text check box selected.) If the form is saved consistently in the Binary format, then the problem is not reproducible.

Secondly, the problem seems to only occur for certain fonts in the list box. MS Sans Serif and Truetype fonts such as Arial are font choices where the problem does not occur. Small Fonts and Courier are examples of fonts in the list box where the problem does occur.

RESOLUTION

The following are three possible workarounds:

  • Explicitly set the height of the list box in the Load event of the form. This will always override whatever height is specified in the property window at design time.

    For example, in the Form_Load event, place the following line of code:
          List1.Height = 3860  'Scalemode of the form is set for Twips
    						
    -or-

  • Consistently save the form in binary format. The problem only appears when the program is run after saving the form in text format. -or-

  • Choose a font for the list box where the problem is not reproducible, such as MS Sans Serif.

Steps to Reproduce the Problem

  1. Start a new Visual Basic project. Form1 appears by default.
  2. Place a list box on the form (it will be called List1 by default) and set the height property of the list box to 6630 twips (or a suitable high value).
  3. In the property window, set the FontName for the list box to Small Fonts. Also, type in a size of 24 for the font (the problem occurs for all sizes of the font, but is most easily seen for larger sizes).
  4. In the Activate event for the form, place the following line of code:
          Debug.Print List1.Height
    						
  5. Run the program by pressing the F5 key. Notice that the Debug window correctly shows the original height of the list box. Stop the program.
  6. Save Form1 in a text format, that is, on the File menu, click Save File As, and check the Save As Text check box.
  7. Run the program by pressing the F5 key. Notice that the debug window still shows the original height of the list box. Stop the program.
  8. Save Form1 once again in text format--when Visual Basic asks if you want to replace Form1, click Yes.
  9. Run the program again. Now the Debug window shows that the list box height has decreased to 6030 twips.
After each successive save of the form in text format, the list box height will decrease every time the project is run. However, the problem only surfaces after the second save of the form in text format.

Modification Type:MajorLast Reviewed:11/3/2003
Keywords:kbbug KB141940