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 7627305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:26:29+00:00 2026-05-31T05:26:29+00:00

I have a panel which displays Form objects. When the Close() method is called

  • 0

I have a panel which displays Form objects. When the Close() method is called on a form, the panel.Controls.Count is modified, the Count is one less. How is this possible?

This is the way I show a form in th panel:

// insertForm is a windows form

insertForm.TopLevel = false;
insertForm.Dock = DockStyle.Fill;
insertForm.FormBorderStyle = FormBorderStyle.None;

this.pnlContent.Controls.Clear();
this.pnlContent.Controls.Add(insertForm);

And when somewhere form.Close() is called, the Controls count of pnlContent is 0. So, how is this possible? What all happens when Close() is called?

  • 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-31T05:26:29+00:00Added an answer on May 31, 2026 at 5:26 am

    Closing a form causes the form to be disposed, which in turn causes it to be removed from its parent’s control-collection.

    If you use a decompiler, you will notice two things:

    1. When you add a control to a ControlCollection, the control’s owner is set as the ControlCollection's owner. ControlCollection.Add(Control value) calls value.AssignParent(this.owner).
    2. When a control is disposed, it removes itself from its owner’s ControlCollection. Essentially, Control.Dispose calls parent.Controls.Remove(this).

    Lesson learned: Don’t use a ControlCollection as general purpose collection-type for Controls. It is deeply integrated into WinForms for control-containment and parent-child relationships. Use this type only when you genuinely require a parent control to contain a child control.

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

Sidebar

Related Questions

I have a panel on an aspx page which contains an UpdatePanel. This panel
I have a hidden div which I reveal with the jquery fadein() method: $(#panel).fadeIn(slow);
I have a form with a panel in which I want to display an
We have a form which displays media items in tab pages of a tab
I have this page which loads quotes. It has a search form wherein if
I have a panel with transparent background which i use to draw an image.
i have a panel (A), which contains 3 other panels (AA, AB, AC). Each
I have a preferences panel in my application in which I have a NSColorWell
I have a button which is in update panel. When I click on button
I have made a basic ascx control which is just a panel with a

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.