0

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

4

2 回答 2

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);
    }
于 2012-10-13T05:14:15.083 回答
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
}
于 2012-10-13T04:15:49.573 回答