打开新窗体后更改按钮的可见性



我有2种形式。形式 1 和形式 5。Form1 有 2 个按钮,用于打开 Form5。我想在显示 Form5 按钮后更改其可见性。我已经将 Form5 按钮的修饰符设置为公共,我也在下面尝试了这段代码,但它不起作用:

public void button1_Click(object sender, EventArgs e)
{
Form5 fr5 = new Form5();
fr5.button1.Visible = true;
fr5.ShowDialog();
}
public void button2_Click(object sender, EventArgs e)
{
Form5 fr5 = new Form5();
fr5.button1.Visible = false;
fr5.ShowDialog();
}

编辑:我已经设置了按钮1。可见 = 真;在 Form5 加载事件中。

感谢您的建议。 :)我已经通过像这样更改代码来解决问题:

public void button1_Click(object sender, EventArgs e)
{
Form5 fr5 = new Form5();      
fr5.Show(this);
fr5.button1.Visible = true;
}
public void button1_Click(object sender, EventArgs e)
{
Form5 fr5 = new Form5();      
fr5.Show(this);
fr5.button1.Visible = false;
}

最新更新