I Googled around but seems my problem happens when two gropboxes are overlapping, in my case they are not overlapping! Problem is that the Visible property of groupbox doesn't work. what am I trying to do is that groupbox1 is visible when program starts and groupbox2 is not, by clicking on a button it should goes invisible and groupbox2 should appear, clicking the same button this action should be done vice versa.

here is my code:

    private void button2_Click(object sender, EventArgs e)
    {
        if (groupBox2.Visible == false)
        {
            groupBox1.Visible = false;
            groupBox2.Visible = true;
        }
        if (groupBox1.Visible == false)
        {
            groupBox1.Visible = true;
            groupBox2.Visible = false;
        }

    }
有帮助吗?

解决方案

Your problem is that after the first if-statement, it immediately checks if groupBox1.Visible is false, which it always will be. It then proceeds to flip it back.

Change the if to an else, or at least and else if and your code will work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top