0

I have 3 GroupBox's that contain various TextBox's and Buttons, I have placed the 3 GroupBox's on top of each other and created 4 buttons so that when one of the buttons is clicked the GroupBox it refers to is shown above the other. To do this I tried .Visible and .BringToFront command. But It didn't work.

private void bunifuFlatButton1_Click(object sender, EventArgs e)
{
    LOGINGROUP.Visible = true;
    LOGINGROUP1.Visible = false;
    LOGINGROUP2.Visible = false;
}

private void bunifuFlatButton2_Click(object sender, EventArgs e)
{

    LOGINGROUP1.Visible = true;
    LOGINGROUP.Visible=false;
    LOGINGROUP2.Visible = false;
}

private void bunifuFlatButton3_Click(object sender, EventArgs e)
{

    LOGINGROUP2.Visible = true;
    LOGINGROUP1.Visible = false;
    LOGINGROUP.Visible = false;

}
Asaf Duba
  • 3
  • 4

1 Answers1

0

Is there a reason why you can't use the TabControl Control?

From my understanding of your description, the button is also placed inside the groupbox. if they are all on top of each other, then you can only click on the button of the top groupbox.

If the above is not the case

This problem is most likely caused by the behaviour of groupboxes in Visual Studio's designer. When a groupbox is placed on top of another in the designer, the top box is automatically placed inside the bottom box, this can be seen in the following code produced by the designer:

        // 
        // groupBox1
        // 
        this.groupBox1.Controls.Add(this.groupBox2);
        this.groupBox1.Location = new System.Drawing.Point(13, 13);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(232, 227);
        this.groupBox1.TabIndex = 0;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "groupBox1";

The highlight is this part:

this.groupBox1.Controls.Add(this.groupBox2);

as you can see, groupBox2 is placed as a control of groupBox1, this causes problems in sending to front since the only control in group is itself and the textboxes that are being overlapped by it.

to fix this, you can simply change

this.groupBoxX.Controls.Add(this.groupBoxY);

to

this.Controls.Add(this.groupBoxY);

or otherwise, simply declare the groupboxes yourself instead of relying on the designer. (however, this requires declaring the textboxes and handlers manually as well)

Rickson
  • 26
  • 4
  • No there is buttons inside the group boxes and also there is a menu with buttons. When I click to a button from menu I want to change the group box – Asaf Duba Mar 09 '19 at 08:40