Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7415017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:12:56+00:00 2026-05-29T07:12:56+00:00

There are two forms in my project and I am trying to add the

  • 0

There are two forms in my project and I am trying to add the controls of Form2’s panel into Form1’s panel.

So,

Form2 form2 = new Form2();
new_panel = form2.Controls["panel1"] as Panel; // form2's panel 

this.panel.Controls.Add(new_panel); // add form2's panel into form1's panel.

And suddenly, the form2.Controls[“panel1”] becomes NULL.

I can’t understand why it happens.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:12:56+00:00Added an answer on May 29, 2026 at 7:12 am

    A control can only have one parent – if you add a control which already has a parent to another control, it will remove itself first.

    From the docs for ControlCollection.Add:

    A Control can only be assigned to one Control.ControlCollection at a time. If the Control is already a child of another control it is removed from that control before it is added to another control.

    If you think about it, that makes sense – a panel needs to know where it is, how big it is etc. It can really logically only be in one place at a time.

    As an aside, I’d recommend using a cast rather than as when you’re proceeding unconditionally as if the cast has worked – that way, if the relevant object isn’t of the right type, you get an exception at the earliest moment of detection, instead of a null reference propagating itself through your system, possibly not being picked up for a long time (making it harder to diagnose the issue and introducing the possibility of data being lost).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a .net project, create two forms {Form1, Form2} and on each form create
In System.Windows.Forms.Application there are two properties called LocalUserAppDataPath and UserAppDataPath . On this computer
I've two nested Forms (form1 and form2) showed modally, i.e. from my MainForm I
I have two forms in my project (Login and Main). What I'm trying to
Backdrop: There are two forms, the main application form and a form to edit
There are just two forms i knew to retrieve resource values in xml files:
I've searched for two days trying to find a solution to this. My problem
My team is diving headfirst into a new project and we are taking the
I currently have a project there are a number of forms that are processed
Let's say I have two forms in a delphi project, I want to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.