如何更改表单的内容

时间:2012-10-13 03:59:50

标签: c# windows winforms

我有一个用C#制作的表单,它有两个文本框和一个按钮。我想知道的是有一种方法来点击按钮。将原始表单的布局更改为只有一个文本框和一个按钮。它们与原始文本框和按钮完全不同,只是为了让您知道。

2 个答案:

答案 0 :(得分:0)

如下面的代码,您可以更改表单内容的布局

private void button1_Click(object sender, EventArgs e)
{
    textBox1.Visible = false; // to hide textbox
    button1.Size = new Size(60, 20);// for changing button layouts
}

答案 1 :(得分:0)

您可以轻松删除原始控件,然后添加新控件。

我相信以下内容应该在没有任何负面诽谤的情况下回答你的问题。

    private void btnThatGetsClicked_Click(object sender, EventArgs e)
    {
        //Remove the existing controls.
        this.Controls.Remove(this.textBox1);
        this.Controls.Remove(this.textBox2);
        this.Controls.Remove(this.btnThatGetsClicked);

        //Create the new controls.
        TextBox TextBox_New = new TextBox();
        Button Button_New = new Button();

        //Add the new controls to this form.
        this.Controls.Add(TextBox_New);
        this.Controls.Add(Button_New);
    }
相关问题