How do I remove a control from a form?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I dynamically add a few user controls to a form, but later, I want to selectively remove some of those user controls from the form. I am trying to do this from the user control with this.ParentForm.Controls.Remove(this), but the control does not disappear. What am I missing? Thanks.
 
* "=?Utf-8?B?SGFycnkgS2Vjaw==?= said:
I dynamically add a few user controls to a form, but later, I want to
selectively remove some of those user controls from the form. I am
trying to do this from the user control with
this.ParentForm.Controls.Remove(this)

Do you want to remove the control from within the implementation of the
control? The code above will (maybe) only work if the control is placed
directly on the form, not if it is placed inside another container like
a panel or groupbox. Maybe 'Parent' instead of 'ParentForm' helps.
 

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

Back
Top