Reputation: 1
My program will prompt the user for a number, i.e. 25. The program will then start the "main form" with 25 controls (textbox). The 25 (or whatever number) of textboxes (or whatever control) will need to be formatted evenly. I will also need to be able to retrieve the text (or another property if I use another control) in order, from left to right and up to down. What is the best method of approaching this?
Upvotes: 0
Views: 62
Reputation: 39132
If WinForms, this is exactly what the FlowLayoutPanel is for. Just add the controls to it and they will arrange themselves automatically, wrapping down to the next row as needed. As Mihai already suggested, you could also keep reference to those controls in a List.
Another option would be to use a TableLayoutPanel. It's a little more difficult to learn and use, but is much more flexible and powerful.
Upvotes: 0
Reputation: 8466
Supposing you are using Windows Forms here. Dynamically create the X controls and add them to the Controls collection of your form. To ease the access to them you can store their reference in a List and set some event handlers too, depending on your needs. You just need to calculate their positions while you add them.
Upvotes: 0
Reputation: 6329
Using WPF MVVM. In a .XAML
file, create a DataTemplate
with the DataType
of a ViewModel that will provide the binding for your TextBox
s, lets call this the TextboxViewModel
. Then using a ItemsControl
element with an ItemsSource
of TextboxViewModel
. You'll be able to instantiate as many TextBox
s as you want and be able to get the result by browsing through your list of TextboxViewModel
.
Upvotes: 2