Changing parent container

Y

Young

Can someone please help? I am trying to move a panel (standard .NET panels)
control to another panel at run time.

I've 2 panels - Panel1 and Panel2. Both's parent are current the form
container.

When I click on a button, I want to make Panel1 the parent of Panel2. I have
change the background color so I can see what is happening. Also, I make
Panel2 smaller than Panel1 to make sure I can see it in Panel1.

Here are the codes in the button click event:

Panel2.Parent = Panel2
Panel2.BringToFront

When I click on the button, I can see Panel2 is no longer visible and
"possible" moved to Panel1. But I cannot see Panel2 within Panel2.

Can someone please help?

TIA
Young
 
P

Pavel Minaev

Can someone please help? I am trying to move a panel (standard .NET panels)
control to another panel at run time.

I've 2 panels - Panel1 and Panel2. Both's parent are current the form
container.

When I click on a button, I want to make Panel1 the parent of Panel2. I have
change the background color so I can see what is happening. Also, I make
Panel2 smaller than Panel1 to make sure I can see it in Panel1.

Here are the codes in the button click event:

Panel2.Parent = Panel2
Panel2.BringToFront

When I click on the button, I can see Panel2 is no longer visible and
"possible" moved to Panel1. But I cannot see Panel2 within Panel2.

After you move the (now child) panel, do you set its Location to
ensure that it is correctly positioned in its parent panel?
 
J

Jerónimo Milea

Hi Young, this is how i will do that:

panel2.Parent = panel1;
panel2.Location = new Point( 10, 10 );
panel2.BringToFront();

Hope that helps
Jerónimo Milea
 
Y

Young

Thanks all for replying.

I did not set the location. It works when I set the location.

Young

Can someone please help? I am trying to move a panel (standard .NET
panels)
control to another panel at run time.

I've 2 panels - Panel1 and Panel2. Both's parent are current the form
container.

When I click on a button, I want to make Panel1 the parent of Panel2. I
have
change the background color so I can see what is happening. Also, I make
Panel2 smaller than Panel1 to make sure I can see it in Panel1.

Here are the codes in the button click event:

Panel2.Parent = Panel2
Panel2.BringToFront

When I click on the button, I can see Panel2 is no longer visible and
"possible" moved to Panel1. But I cannot see Panel2 within Panel2.

After you move the (now child) panel, do you set its Location to
ensure that it is correctly positioned in its parent panel?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top