tags:

views:

672

answers:

3

IDE: Microsoft Visual Studio Professional 2008

Language: C#

Background: I have one form and two groupboxes that are going to be used as preference catagory groupboxes. My problem is that everytime I drag one groupbox on top of the other (hide/show groupboxes upon listview catagory select), the base groupbox auto-parents the second groupbox I just dragged on top.

Question: How do I stop the two groupboxes from auto-parenting themselves when dragged on top of one another?

// Edit;

Q) I assume you are trying to acheive a layout where you swap out the visible box? --Mitchel Sellers

A) Yes I am. I know I could do it at runtime but I'd like to make that my last option in case there is a more appropriate solution.

A: 

The behavior of the group box is that you can drag controls into it, including other group box controls. If you let go of the mouse while dragging it over, it will become a child of that groupbox, and AFAIK there is no way to change the designer. Unless you work potentially with send to back first, than load the other on top.

I assume you are trying to acheive a layout where you swap out the visible box?

Mitchel Sellers
I assume you are trying to acheive a layout where you swap out the visible box?Yes I am. I Know I could do it at runtime but I'd like to make that my last option in case there is a more appropriate solution.
+1  A: 

You may consider resizing your second GroupBox into position over the first. Drag one side or one corner of the second group box until it covers the first GroupBox and continue to resize the second GroupBox until it is positioned as you desire.

Also available, in the Layout Toolbar, are the alignment and sizing buttons. Select both of your GroupBoxes to enable these options. The GroupBox displaying white grab handles is the one that will remain stationary when you use the alignment and sizing buttons, which include options to "Make Same Size" and "Align Middle".

Furthermore, don't forget the keyboard right in front of you. The arrow keys will move the selected controls. Try holding various combinations of [ctrl] [alt] and [shift] while using the arrow keys.

Dan Koster
A: 

Had the same problem but solved it by moving the groupbox a bit somwhere in the form where it wouldn't bother. Then I turned the visible flag on. There must of course be a simpler and better solution but this one worked for me. The positive thing is that you can easier design the groupboxes in VS since they will pop up on the right spot during execution any way...

    private void radioButton1_CheckedChanged(object sender, EventArgs e)
    {
        groupBox1.Location = new System.Drawing.Point(198, 234);
        groupBox2.Location = new System.Drawing.Point(660, 234);
        groupBox1.Visible = true;
        groupBox2.Visible = false;

    }

    private void radioButton2_CheckedChanged(object sender, EventArgs e)
    {
        groupBox1.Location = new System.Drawing.Point(660, 234);
        groupBox2.Location = new System.Drawing.Point(198, 234); 
        groupBox1.Visible = false;
        groupBox2.Visible = true;
    }