-2

我有一个垂直面板,它有一个按钮,该按钮必须显示一个文本框,该文本框将插入名称并在面板内创建一个按钮

我不知道如何显示文本框和一个按钮以在其上创建一个按钮 = /

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;




        }
4

1 回答 1

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;
于 2013-06-10T04:47:22.693 回答