So I have a form that gets dynamically generated by a script to have a label and a text box for every string pulled as an argument. I want the user to fill in each text box then select the OK button. Afterwards I want to process each item of each text box. Before when there was only 1 item, I wrote a very simple property to obtain the value of the text box.
Public string Text { get { return textbox1.Text; } }
I was hoping I could do something equally as elegant with a dynamic number of text boxes.
Public string [] Text { get { return **Each text box text as an array**; } }
I've been thinking about it for a while and I can't think of an elegant way to set this up, here is how the text boxes are added to the form...
string[] keywords = Environment.GetCommandLineArgs();
int placement = 10;
foreach (string keyword in keywords)
{
if (keyword == keywords[0])
continue;
Label lbl = new Label();
lbl.Text = keyword;
lbl.Top = placement;
this.Controls.Add(lbl);
TextBox txt = new TextBox();
txt.Top = placement;
txt.Left = 100;
this.Controls.Add(txt);
placement += 20;
}
I could loop through each text box's text upon the form closing and populate the public array with the values, but I would rather come up with something a little more elegant and get out of the habit of doing things by force. Anybody have any cool ideas of how to accomplish this? I'm thinking I could add all the text boxes to an array and then have the string property somehow grab the text of the text box specified, or just make the text box array the public property instead. Is there a way to write something like this...
Public string [] Text { get { return TextBoxArray[**value trying to be gotten**].Text; } }
or is this to much for a property and needs to be a method instead? Any other ideas anybody has? I realize it's a bit of a trivial question and could be solved in any number of ways, I'm just looking to broaden my horizons on cool ways to accomplish something like this.