Search code examples
vb6

Position a form on a form in vb6


I need to open a second form and position it in a particular location on the first form opened.

Explain: I added a panel to the original form and as I was putting controls on it, I got a message that I could not add any more controls. So...

There is an existing panel that I need to cover up with a second form and have it remain covered even if the original form is dragged about the screen. The second form will cover it, but I need to know how to position it in reference to the first form.

The only references I can find are how to position it on the screen, not another form.


Solution

  • There's certainly no easy way to do that (a form can't host another form). The limit you encountered was the max number of named controls you can have on a form (254, see https://msdn.microsoft.com/en-us/library/aa240865(v=VS.60).aspx).

    However, a control array only counts once to that limit. So instead of adding a new control (for instance text boxes) for every input field, add them as new elements of a text box array. The difference in code is that you'll reference the text boxes by index instead of unique name (you can use constants as index parameters to identify the different input fields, such as name, address, etc).