Taborder for Dynamically-Created Controls
-
My code creates textboxes based on data from a file. I need to be able to retreive the text from each dynamically-created textbox. By the way, each textbox is contained in a splitcontainer control (spc_Questions). Here is the code that creates each textbox:
for (cntr = 0; cntr <; NumQ; cntr++) { input = sr.ReadLine(); newTextBox = new System.Windows.Forms.TextBox(); newTextBox.Size = new Size(25, newTextBox.Size.Height); newTextBox.MaxLength = 1; newTextBox.CharacterCasing = CharacterCasing.Upper; newTextBox.TabStop = true; newTextBox.TabIndex = cntr; newTextBox.Location = new Point(spc_Questions.Panel1.Right - newTextBox.Size.Width - 10, vHeight); newTextBox.Tag = cntr.ToString(); newTextBox.Show(); spc_Questions.Panel1.Controls.Add(newTextBox); }
Any help would be appreciated. :) -
My code creates textboxes based on data from a file. I need to be able to retreive the text from each dynamically-created textbox. By the way, each textbox is contained in a splitcontainer control (spc_Questions). Here is the code that creates each textbox:
for (cntr = 0; cntr <; NumQ; cntr++) { input = sr.ReadLine(); newTextBox = new System.Windows.Forms.TextBox(); newTextBox.Size = new Size(25, newTextBox.Size.Height); newTextBox.MaxLength = 1; newTextBox.CharacterCasing = CharacterCasing.Upper; newTextBox.TabStop = true; newTextBox.TabIndex = cntr; newTextBox.Location = new Point(spc_Questions.Panel1.Right - newTextBox.Size.Width - 10, vHeight); newTextBox.Tag = cntr.ToString(); newTextBox.Show(); spc_Questions.Panel1.Controls.Add(newTextBox); }
Any help would be appreciated. :) -
danielhasdibs wrote:
Any help would be appreciated.
Im sure it would be, but you forgot to ask a question! :confused:
Question = How?
-
My code creates textboxes based on data from a file. I need to be able to retreive the text from each dynamically-created textbox. By the way, each textbox is contained in a splitcontainer control (spc_Questions). Here is the code that creates each textbox:
for (cntr = 0; cntr <; NumQ; cntr++) { input = sr.ReadLine(); newTextBox = new System.Windows.Forms.TextBox(); newTextBox.Size = new Size(25, newTextBox.Size.Height); newTextBox.MaxLength = 1; newTextBox.CharacterCasing = CharacterCasing.Upper; newTextBox.TabStop = true; newTextBox.TabIndex = cntr; newTextBox.Location = new Point(spc_Questions.Panel1.Right - newTextBox.Size.Width - 10, vHeight); newTextBox.Tag = cntr.ToString(); newTextBox.Show(); spc_Questions.Panel1.Controls.Add(newTextBox); }
Any help would be appreciated. :) -
you need to set the TabIndex Property
Don't be overcome by evil, but overcome evil with good
It's set after I create the text box.
newTextBox.TabIndex = cntr;
I've been trying to use the SelectNextControl() method to get to each textbox control, but it keeps selecting the splitcontainer instead of the textboxes. -
It's set after I create the text box.
newTextBox.TabIndex = cntr;
I've been trying to use the SelectNextControl() method to get to each textbox control, but it keeps selecting the splitcontainer instead of the textboxes. -
My code creates textboxes based on data from a file. I need to be able to retreive the text from each dynamically-created textbox. By the way, each textbox is contained in a splitcontainer control (spc_Questions). Here is the code that creates each textbox:
for (cntr = 0; cntr <; NumQ; cntr++) { input = sr.ReadLine(); newTextBox = new System.Windows.Forms.TextBox(); newTextBox.Size = new Size(25, newTextBox.Size.Height); newTextBox.MaxLength = 1; newTextBox.CharacterCasing = CharacterCasing.Upper; newTextBox.TabStop = true; newTextBox.TabIndex = cntr; newTextBox.Location = new Point(spc_Questions.Panel1.Right - newTextBox.Size.Width - 10, vHeight); newTextBox.Tag = cntr.ToString(); newTextBox.Show(); spc_Questions.Panel1.Controls.Add(newTextBox); }
Any help would be appreciated. :)Please Try this Code , it's about buttons Control , but it think you will understand my idea ......
public partial class Form1 : Form { public Button sb; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { for (int x = 0; x < 10; x++) { sb = new Button(); sb.Size = new Size(17, 17); sb.Location = new Point(x * 17, 10); sb.Tag = (x).ToString(); sb.Visible = true; sb.Click += new EventHandler(sb_Click); Controls.Add(sb); } this.Size = new Size(176, (12 * 17) + 7); } private void sb_Click(object sender, System.EventArgs e) { Button sb = sender as Button; this.Text = sb.Tag.ToString(); }
I know nothing , I know nothing ...
-
what are you using passing in the first parameter in SelectNextControl()?
Don't be overcome by evil, but overcome evil with good
Here's a sample of the SelectNextControl() method I used.
string[] textFromControl = new string[10]; Control nextControl = new Control(); spc_Questions.Focus(); for (cntr = 0; cntr <; NumControls; cntr++) { this.SelectNextControl(nextControl, true, true, true, true); nextControl = this.ActiveControl; nextControl.Focus(); textFromControl[cntr] = nextControl.Text; }
-
Please Try this Code , it's about buttons Control , but it think you will understand my idea ......
public partial class Form1 : Form { public Button sb; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { for (int x = 0; x < 10; x++) { sb = new Button(); sb.Size = new Size(17, 17); sb.Location = new Point(x * 17, 10); sb.Tag = (x).ToString(); sb.Visible = true; sb.Click += new EventHandler(sb_Click); Controls.Add(sb); } this.Size = new Size(176, (12 * 17) + 7); } private void sb_Click(object sender, System.EventArgs e) { Button sb = sender as Button; this.Text = sb.Tag.ToString(); }
I know nothing , I know nothing ...
Thank you! Below is how I implemented it for anyone who needs it (this is in a splitcontainer -- spc_Questions):
for (cntr = 0; cntr <; NumControls; cntr++) { newTextBox = new System.Windows.Forms.TextBox(); newTextBox.Size = new Size(25, newTextBox.Size.Height); newTextBox.Location = new Point(spc_Questions.Panel1.Right - newTextBox.Size.Width - 10, cntr * setHeight); // Tag needed to identify controls newTextBox.Tag = cntr.ToString(); newTextBox.TextChanged += new EventHandler(newTextBox_TextChanged); newTextBox.Show(); spc_Questions.Panel1.Controls.Add(newTextBox); } void newTextBox_TextChanged(object sender, EventArgs e) { TextBox Text = sender as TextBox; ControlTexts[int.Parse(Text.Tag.ToString())] = Text.Text; }
Thank you, again!