I know the limit for named controls is 254, beyond that you have to use control arrays. But it seems we have hit the limit for arrays too. Any idea what that absolute limit is?
The three basic VB controls are the Label, Textbox, and Button; these are the controls we will be working with for this program.
In Visual Basic, a control array is a group of related controls in a Visual Basic form that share the same event handlers. Control arrays are always single-dimensional arrays, and controls can be added or deleted from control arrays at runtime.
Visual Basic Form is the container for all the controls that make up the user interface. Every window you see in a running visual basic application is a form, thus the terms form and window describe the same entity. Visual Studio creates a default form for you when you create a Windows Forms Application.
A TextBox control is used to display, accept the text from the user as an input, or a single line of text on a VB.NET Windows form at runtime. Furthermore, we can add multiple text and scroll bars in textbox control. However, we can set the text on the textbox that displays on the form.
There is no absolute limit. If you put enough controls on the form, you'll eventually run out of memory. I made a test app that loads command buttons into a control array. My first run stopped with an "Out of memory" error at around 6900 buttons. I shut down a few other apps and was able to load nearly 8200. I did the same thing with text boxes and got different results (about 7300 before and 8600 after). Different controls consume different amounts of memory, so there really is no way to specify an exact number of controls that you can put on a form.
We have a records management system written in VB6 and there is a UI guideline that says each record should have exactly one data entry form associated with it (i.e. can't open up other windows). As a result of this policy, one of the more complex record types in our system now has a form with a total of 659 individual controls. We had run into the 256 named controls limit, and then converted many of the controls to control arrays over time. Recently, we squeezed room for 5 or 6 new controls, after going through the entire form and converting the few remaining standalone controls to control arrays.
This is one time where I would like to break the rules, but that would involve quite a bit of refactoring to use a multiple form approach.
In any event, you can fit at least 659 controls on a form, but I've never been able to find out what the true absolute limit is (and I'm not sure that I want to).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With