【问题标题】:windows form button show textbox and add name for new button [closed]Windows窗体按钮显示文本框并为新按钮添加名称[关闭]
【发布时间】:2013-06-05 16:42:17
【问题描述】:

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

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

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;




        }

【问题讨论】:

  • 带有文本框的名称或文本框的文本??

标签: c# button textbox panel


【解决方案1】:

如果你想显示文本框的文本,只需编写以下代码

    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-06
    • 2014-06-08
    • 2013-06-05
    • 1970-01-01
    • 2012-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多