Click here to Skip to main content
13,003,094 members (64,062 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I' trying to copy one panel into another panel which is created at run time but the old panel keeps disappearing , can you tell me what's wrong ?

my code :

Friend withevent NewPanel As New Panel
NewPanel = Panel1
NewPanel.Top=Panel1.Top + Panel1.Height 
Posted 26-Sep-12 2:10am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You're not really creating a new panel.

What you're doing is creating a new pointer for a Panel called NewPanel

And yes, for a second you're creating a new Panel and assigning it to the pointer. But then you immediately change the pointer for the new panel to point to the old one.

So NewPanel == Panel1

This isn't creating a copy. Objects such as Panels exist in the Stack area of memory.

This mean that NewPanel = Panel1 isn't creating a copy. It's just changing NewPanel so it points to the same memory location as Panel1. NewPanel and Panel1 are the same Panel instance.

To create a copy of the panel you'll have to create a new panel and then configure it using your code. So instead of NewPanel = Panel1 you'd have something similar to this:

NewPanel.Left = Panel1.Left
NewPanel.Top = Panel1.Top

Adding all the properties you need to configure the new panel as the old one was.

You then need to do a similar thing for the all the controls within the panel.

Truth be told, that's a lot of hard work. I'd create a custom control which contains a Panel and all the controls contained within the Panel. Then you need only create a new instance of your custom control.

The following is an introduction to developing custom controls.[^]
ayat abukhadra 26-Sep-12 8:43am
OK , i got it =D i didn't know that information , thank you =D I'll try to create the custom control =D

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 26 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100