Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add and position controls dynamically

Status
Not open for further replies.

marble

Programmer
Mar 17, 2001
22
0
0
CA
Hi all,

I have searched the faw's and found small snippets of code but not what i need.

I would like to place 1, 4, 9 or 16 picture boxes on a form dynamically. The number of pictureboxes is determined by a combo box value.

The problem is that I would like to add the controls dynamically at runtime and then position these pictures on the screen. The screen can have:

1 x 1 = 1
2 x 2 = 4
3 x 3 = 9
4 x 4 = 16

I do not want to use a control array, I was told that a control collection is much better.


Can someone help me, please ...

Thankyou in advance,

Marble



 
Hi,

The ONLY way to do it is with a Control Array, but that sounds to me exactly the same as a control collection!

You'd have one picturebox, set the Index to 0 and make it the size you want all the others to appear at. Then in your Combo code do this:

Sub Combo1_Click

' Start off by removing all but the first PictureBox:
For Each PBox in Picture1
If (PBox.Index <> 0) then Unload PBox
Next PBox

' Get the number of picture boxes to create...
a& = Val(Combo1.List(Combo1.ListIndex))

For b& = 1 to a&
Load Picture1(b&)
' Code here to position it...
Picture1(b&).Move x, y
Picture1(b&).Visible = True
Next b&

End Sub

Hope this helps.


- Andy
_______________________________
&quot;On a clear disk you can seek forever&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top