Results 1 to 1 of 1

Thread: positioning runtime loaded controls

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    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:
    1. Private Sub Form_Load()
    2.       loadmore Text1, 39, 3, 400, 200
    3.       ' name of control, with index 0, should be in correct position for all other controls to align to
    4.       ' number of controls to load, in addition to original with index 0
    5.       ' number of controls in each row
    6.       ' horizantal and vertical space between columns and rows
    7.        
    8.       End Sub
    9.       Sub loadmore(c As Object, cnt As Integer, rowcnt As Integer, hgap As Integer, vgap As Integer)
    10.       Dim w As Integer, h As Integer, i As Integer
    11.       w = c(0).Width + hgap ' control width and space between
    12.       h = c(0).Height + vgap
    13.       For i = 1 To cnt
    14.           Load c(i)
    15.           With c(i)
    16.               .Move c(0).Left + ((i Mod rowcnt) * w), c(0).Top + ((i \ rowcnt) * h)
    17.               .Visible = True
    18.           End With
    19.           c(i) = "control " & i ' for testing purposes only, only works for textboxes and labels, or other controls that have a suitable default property
    20.       Next
    21.       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
  •  



Click Here to Expand Forum to Full Width