/// <summary> /// Called after a child control is removed from this control. The default behavior is to call InvalidateAutoSize(). /// </summary> protected virtual void OnChildRemoved(int index, Control child) { InvalidateAutoSize(); }
/// <summary> /// Remove the given control from this control's list of children. /// </summary> public void RemoveChild(Control child) { if(child.Parent != this) throw new InvalidOperationException(); RemoveChildAt(children.IndexOf(child)); }
public void AddChild(Control child) { if (child.Parent != null) { child.Parent.RemoveChild(child); } AddChild(child, ChildCount); }
public void AddChild(Control child, int index) { if (child.Parent != null) { child.Parent.RemoveChild(child); } child.Parent = this; if (children == null) { children = new List<Control>(); } children.Insert(index, child); OnChildAdded(index, child); }
// Call this method once per frame on the root of your control heirarchy to draw all the controls. // See ControlScreen for an example. public static void BatchDraw(Control control, GraphicsDevice device, SpriteBatch spriteBatch, Vector2 offset, GameTime gameTime) { if (control != null && control.Visible) { spriteBatch.Begin(); control.Draw(new DrawContext { Device = device, SpriteBatch = spriteBatch, DrawOffset = offset + control.Position, GameTime = gameTime }); spriteBatch.End(); } }