public virtual void RemoveChild(GuiWidget childToRemove) { if (!Children.Contains(childToRemove)) { throw new InvalidOperationException("You can only remove children that this control has."); } childToRemove.ClearCapturedState(); childToRemove.hasBeenRemoved = true; Children.Remove(childToRemove); childToRemove.parent = null; childToRemove.OnParentChanged(null); OnChildRemoved(new GuiWidgetEventArgs(childToRemove)); OnLayout(new LayoutEventArgs(this, null, PropertyCausingLayout.RemoveChild)); Invalidate(); }