Microsoft KB Archive/229756

= INFO: Maximum Number of Controls on a Form =

Article ID: 229756

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

-



This article was previously published under Q229756



SUMMARY
This articles discusses the number of controls you can add to a form in a Visual Basic project and ways to work around these limitations.



MORE INFORMATION
The maximum number of controls allowed on a single form depends on the type of controls used and available system resources. However, there is a fixed limit of 254 control names per form.

NOTE: Although you can have up to 254 control names in a form, a large number of controls in a form will severely degrade your program's performance. In some cases, you will experience out-of-memory error. To maximize the performance of your program, you should minimize the number of controls in each form.

Here are three ways to work around the control name and system resource limitations:
 * Use a control array - instead of using several instances of a control in a form, create a control array for all the similar controls on the form. Members of a control array share the same control name.
 * Dynamically create the controls as required - instead of loading all the controls on a form when you first display the form, try loading the controls as needed. This only works well when you potentially need many controls, but will use only a few of them at any given time. For more information about dynamically creating controls, please see the following article in the Microsoft Knowledge Base:

190670 HOWTO: Dynamically Add Controls to a Form with Visual Basic 6.0
 * Put your controls on a UserControl - similar to using a control array, you can create a UserControl that contains your controls and then add the UserControl to your project. For example, if you need a form that displays 500 text boxes, create a UserControl that contains 250 text boxes, and put two instances of your UserControl on the form. You now have 500 text boxes on the form, but only two controls.

