positioning runtime loaded controls
i was trying to find some example to add to a thread, but could not find something suitable
here is a generic proceedure to load controls in a control array, to try it out, just add the code to a new project with a textbox or someother control with index set to 0 to make control array, and in the position you want it to appear, specify the number of controls to add and the number in each row, also what gap you want between the columns and rows
vb Code:
Private Sub Form_Load()
loadmore Text1, 39, 3, 400, 200
' name of control, with index 0, should be in correct position for all other controls to align to
' number of controls to load, in addition to original with index 0
' number of controls in each row
' horizantal and vertical space between columns and rows
End Sub
Sub loadmore(c As Object, cnt As Integer, rowcnt As Integer, hgap As Integer, vgap As Integer)
Dim w As Integer, h As Integer, i As Integer
w = c(0).Width + hgap ' control width and space between
h = c(0).Height + vgap
For i = 1 To cnt
Load c(i)
With c(i)
.Move c(0).Left + ((i Mod rowcnt) * w), c(0).Top + ((i \ rowcnt) * h)
.Visible = True
End With
c(i) = "control " & i ' for testing purposes only, only works for textboxes and labels, or other controls that have a suitable default property
Next
End Sub
should work for any control that can be in a control array,
up to you to make sure that the form is big enough to display the controls, else put in a frame or picturebox and add scrollbars