【发布时间】:2020-05-09 12:21:27
【问题描述】:
我想知道是否有人可以帮助我。
我正在尝试使用一组文本框构建用户控件。这个想法是能够显示信息的集合。
我可以获取一个要更新的文本框,但我无法获取一个数组来执行相同的操作。
函数 _aTextBox() 是从我的主程序上的 2 个按钮调用的,如下所示:
private void button1_Click(object sender, EventArgs e)
{
ucTextBox1._aTextBox("Hello");
}
private void button2_Click(object sender, EventArgs e)
{
ucTextBox1._aTextBox("World");
}
My User Control code is below:
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);
}
}
}
*在标有 // ********************* 的行,txt[0].Text 保存正确的字符串。但是,它从不显示它!!!*
欢迎提出任何建议。非常感谢您抽出宝贵时间阅读本文。
约翰
【问题讨论】:
标签: c# textbox user-controls