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.
 
Back
Top