|
-
Apr 27th, 2009, 06:42 AM
#1
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
Last edited by westconn1; Dec 30th, 2009 at 04:12 PM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|