我有一个垂直面板,它有一个按钮,该按钮必须显示一个文本框,插入名称并在面板内创建一个按钮
我不知道如何显示文本框和一个按钮来创建一个按钮= /
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Visible)
textBox1.Visible = false;
else
textBox1.Visible = true;
Button c = new Button();
c.Location = new Point(15, x);
c.Text = "novo"; //here comes with the button name, need textbox receives the name and create a button with the name of the textbox.
panel1.Controls.Add(c);
x += 10 + c.Size.Height;
}
答案 0 :(得分:0)
如果你想显示文本框的文本,只需编写以下代码
Button c = new Button();
c.Location = new Point(15, x);
c.Text = textBox1.Text;
panel1.Controls.Add(c);
x += 10 + c.Size.Height;
如果您想显示文本框的名称,请编写以下代码
Button c = new Button();
c.Location = new Point(15, x);
c.Text = textBox1.Name.ToString();
panel1.Controls.Add(c);
x += 10 + c.Size.Height;