Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a panel with three groupboxes. Each groupbox has its control(combobox, labels, textboxes etc.). Groupbox1 is default when the panel is loaded. A combobox with two items determines when groupbox2 becomes visible while groupbox1 disappear so that the user can input certain information in it.

from properties, groupbox1: visible = "true" groupbox2: visible = "false" groupbox3: visible = "false"

My intention is that,

1) Item one does nothing when selected since default groupbox1 and its controls are already visible.

2) Item two makes groupbox1 and its controls hidden and groupbox2 and its controls visible. A combobox with similiar function is in groupbox2 exist to enable the switch back to the groupbox1 is item two is selected.

All this is supposed to occurs during runtime.

There is a third groupbox3 which is triggered by a button on the panel. I intend to make the groupbox3 visible whilst making everything on the panel look dim until a close button is clicked on groupbox3. i want to be able to make changes in the labels in groupbox1 and groupbox2 using a combobox control in groupbox3.

My Problem is

1)how do i make groupbox1 or groupbox2 on the panel appear faded and not totally hidden, while groupbox3 pops up like a messagebox,and also when i click a close button on groupbox3, groupbox3 closes while groupbox1 or groupbox2 becomes visible again

What I have tried:

C#
 private void panel1_Paint(object sender, PaintEventArgs e)
{

}

private void cb1_SelectedIndexChanged(object sender, EventArgs e)
{
    gb1.Visible = cb1.SelectedIndex == 0;

    switch (cb1.SelectedIndex)
    {
        case 0:
            gb1.Visible = true;
            gb2.Visible = false;
            break;
        case 1:
            gb2.Visible = true;
            gb1.Visible = false;
            break;
    }
}

private void cb2_SelectedIndexChanged(object sender, EventArgs e)
{
    gb2.Visible = cb2.SelectedIndex == 0;

    switch (cb1.SelectedIndex)
    {
        case 0:
            gb2.Visible = true;
            gb1.Visible = false;
            break;
        case 1:
            gb1.Visible = true;
            gb2.Visible = false;
            break;
    }
}

private void bt1_Click(object sender, EventArgs e)
{
    gb3.Show();
    gb1.Hide();
    gb2.Hide();
}

private void bt2_on_gb3_Click(object sender, EventArgs e)
{
    gb3.Hide();
    gb1.Show();
    gb2.Show();
}
Posted
Updated 7-Oct-19 2:37am
v8

1 solution

The way I'd do it is to create each GroupBox and it's associated controls as a separate UserControl, and use Events to signal to the parent panel or form that a change is required. Then it's easy: set the Visible property of all UserControls to false and then set the one you want to see true

This also means that the GroupBoxes become independent, and can be changed / added to with impunity because the "outside world" doesn't need to know what controls they contain.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900