Rediscovering Control Array

falled

Member
Joined
Sep 16, 2006
Messages
20
Programming Experience
Beginner
I'm newbie in VB .NET.

I'm working in a Software Company developing applications for stores and today, I've encountered my first real challenge, How to create runtime controls????

I come from flash and it's very easy to create this kind of arrays
createEmptyMovieClip("name",...)

But if I wanna create an indeterminate number of controls, and this number I only can read it in run time mode??

I've spend all this day surfing on the internet looking for any answer, but unfortunatelly I've founded nothing. But suddenly, after trying many combinations I found This:

//Author: Xavier Colomer Pages
//Ncatdesigner@hotmail.com
Dim nRows As Integer
nRows = 5
Dim count As Integer
Dim Array(nRows) As Object
For count = 1 To nRows Step 1
Array(count) =
New Windows.Forms.Button
Array(count).Name =
"Button" & count
Array(count).Top = 100
Array(count).Text =
"Button" & count
Array(count).BackColor = Color.Green
Array(count).width = 100
Array(count).Height = 100
Array(count).Left = 100 + (Array(count).Width + 10) * count
Me.Controls.Add(Array(count))
Next count

I think it's really easy now.

Thank you all for trying to help me and as I hope this little code can help other people to get his desired results coding his apps.

Read you soon sorry for my bad writting!

--Work a little, enjoy a lot, live forever, die never
 
Please keep each topic to one thread. You've created two other threads that are addressing this same topic. They have now been deleted.

You may also want to consider using a TableLayoutPanel, which not only allows you to create a group of controls within a container, but it also helps you lay them out sensibly on the form as well.
 
Back
Top