How to dynamically change group groups on button click?

I am creating an application in Visual Studio 2012 (C # / Winforms). What I mean is depicted by the image:enter image description here

When you press button "1", the content in the group box will change, the same with buttons 2 and 3.

I am currently using the following:

private void button2_Click(object sender, EventArgs e)
{
    this.Controls.Remove(this.groupBox1);
    this.Controls.Add(this.groupBox2);
}

      

My questions:

a) Using this, will runtime performance work as all the controls will be active (albeit hidden) at the same time?

b) Think if I continue to use the current method, can I create a new workspace and create each group package in different windows?

c) Is there a workaround for my current method?

Thank.

+3


source to share


1 answer


It would be better to simply:

private void button2_Click(object sender, EventArgs e)
{
    groupbox2.Visible = true;
    groupbox1.Visible = !groupbox2.Visible;
}

      

and similarly

private void button1_Click(object sender, EventArgs e)
{
    groupbox1.Visible = true;
    groupbox2.Visible = !groupbox1.Visible;
    groupbox3..... = !groupbox1.Visible; //etc
}

      

This will be more realistic, and adding and removing controls can have complex guis side effects where the controls won't be set correctly.



To answer you:

a) Not much, but as I said it is better to toggle the visibility.

b) What is a workspace? Of course, you can promote your approach from any window or form. But if you add group groups of one form to another, the group groups from the first form will be removed.

c) My answer ..

+3


source







All Articles