Hello everyone,
I am attempting to build a User Control with a collection of TextBoxes. The idea is to be able to display a collection of information.
I can get a single Textbox to update, but I just can't get an array to do the same thing.
The function _aTextBox() is called from 2 buttons on my main program as follows:
- private void button1_Click(object sender, EventArgs e)
- {
- ucTextBox1._aTextBox("Hello",0);
- }
- private void button2_Click(object sender, EventArgs e)
- {
- ucTextBox1._aTextBox("World",1);
- }
Any and all suggestions welcomed . Many thanks for your time reading this.
My User Control code is below:
At the line marked with // *********************, txt[0].Text holds the correct string. However, it never displays it!!!
- namespace ucTextBox
- {
- public partial class ucTextBox: UserControl
- {
- public ucTextBox()
- {
- InitializeComponent();
- }
- TextBox[] txt = new TextBox[2];
- private void DisplayTextBoxes()
- {
- txt[0] = new TextBox();
- txt[0].Location = new System.Drawing.Point(20, 48);
- this.Controls.Add(txt[0]);
- }
- public void _aTextBox(string text)
- {
- DisplayTextBoxes();
- txt[0].Visible = false;
- txt[0].Text = text;
- txt[0].Visible = true;
- txt[0].Invalidate();
- txt[0].Update();
- txtValue.Visible = true;
- txtValue.Text = text;
- txt[0].ResumeLayout(true);
- }
- }
- }