How to assign existing Controls to Different Parents

I have two panel controls let's say x and y.

I want to use y over x but without y being a child of x.

Is there any way to acomplish these.

Thanks.

[176 byte] By [Rgranada] at [2007-12-28]
# 1

If I understand you, your problem is Y becomes inside X.

Ok, create a form, add panel X. Now add panel Y.

As you know, as soon as you move it over, it goes inside.

You can break them apart with cut and paste,

select Y.
Cut.
Click on Form.
Paste.

To move them over each other, you can just change the location prop, you could use code todo this.

Or, the code way.

this.x = new System.Windows.Forms.Panel();
this.y = new System.Windows.Forms.Panel();
this.x.SuspendLayout();
this.SuspendLayout();
//
// x
//
this.x.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.x.Controls.Add(this.y);
this.x.Location = new System.Drawing.Point(40, 48);
this.x.Name = "x";
this.x.Size = new System.Drawing.Size(200, 100);
this.x.TabIndex = 0;
//
// y
//
this.y.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.y.Location = new System.Drawing.Point(-1, -1);
this.y.Name = "y";
this.y.Size = new System.Drawing.Size(200, 100);
this.y.TabIndex = 2;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(340, 305);
this.Controls.Add(this.x);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.x.ResumeLayout(false);
this.ResumeLayout(false);

Remove the YELLOW code to just after GREEN code add

this.Controls.Add(this.y);

So you have

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(340, 305);
this.Controls.Add(this.x);
this.Controls.Add(this.y);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.x.ResumeLayout(false);
this.ResumeLayout(false);

Then change the location of y to match the location of x.

Why do you need todo this? there maybe better ways off doing what you want.

Steve.Drake at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic IDE...
# 2

I think i found a way that works based on your description.

My final goal was to have e "floating" panel over onother one in a way i could toggle the visible prop of the underlying panel without afecting the "floating" one.

Based on your description i could position the panel without having it in the underlying container, then with some use of the BringToFront method i think i have what i want.

Thank you.

Rgranada at 2007-9-4 > top of Msdn Tech,Visual Basic,Visual Basic IDE...