[2005] How to add array of controls programmatically
Hello Everybody :wave: ,
If any one can help me in this simple question I will be very grateful.
Let say we have a textbox and a button in a form. I want If I write 3 in the textbox and click ok then an array of 3 buttons (or any controls) will apear in the form.
if I write 2 then array of 2 buttons will appear and so on.
Thank you for your time.
Re: [2005] How to add array of controls programmatically
The tricky part of creating controls dynamically is to set its location.... At run time, you'll never know how many controls will be created. Supposed your user enter 1000 in the textbox, you can easily create 1000 buttons but to fit them all in your form will be a problem. So a work around for this is to create controls and place them on a panel which has the scrolling ability.
Re: [2005] How to add array of controls programmatically
Have you searched the forums for the answer. There are loads and loads of examples of dynamically creating controls.
As for how many to create you could read the number from the text box
VB Code:
Dim numControls As Integer = Cint(textBox.Text)
For i As Integer = 0 To numControls
'Place you control creation and adding code here
Next
Also, the point made by Stanav is very good. Too many and you run into problems.
You could dictate a certain number per row by updating the x location and then update both the y and x location points when you want a new row of the controls for examples. Scrolling is a good option.
Re: [2005] How to add array of controls programmatically
first thanks you all,
This is just simple program, I want only take the idea of dynamic creating controls and
view it in the form at specific location.