#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2007 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Nuclex.Windows.Forms {
/// Collection of controls embedded in another control
public class EmbeddedControlCollection : Control.ControlCollection {
#region class ControlEventArgs
/// Arguments class for events that need to pass a control
public class ControlEventArgs : EventArgs {
/// Initializes a new event arguments provider
/// Control to be supplied to the event handler
public ControlEventArgs(Control control) {
this.control = control;
}
/// Obtains the control the event arguments are carrying
public Control Control { get { return this.control; } }
/// Control that's passed to the event handler
private Control control;
}
#endregion // class ControlEventArgs
/// Raised when a control has been added to the collection
public event EventHandler ControlAdded;
/// Raised when a control is removed from the collection
public event EventHandler ControlRemoved;
/// Initializes a new instance of the EmbeddedControlCollection class
///
/// A System.Windows.Forms.Control representing the control
/// that owns the control collection
///
EmbeddedControlCollection(Control owner) : base(owner) { }
/// Adds the specified control to the control collection
///
/// The System.Windows.Forms.Control to add to the control collection
///
public override void Add(Control value) {
base.Add(value);
OnControlAdded(value);
}
/// Removes the specified control from the control collection
///
/// The System.Windows.Forms.Control to remove from the EmbeddedControlCollection
///
public override void Remove(Control value) {
base.Remove(value);
OnControlRemoved(value);
}
/*
/// Adds an array of control objects to the collection
///
/// An array of System.Windows.Forms.Control objects to add to the collection
///
public override void AddRange(Control[] controls) {
base.AddRange(controls);
}
/// Removes all controls from the collection
public override void Clear() {
base.Clear();
}
/// Removes the child control with the specified key
/// The name of the child control to remove
public override void RemoveByKey(string key) {
base.RemoveByKey(key);
}
*/
///
/// Called when a control has been added to the collection,
/// fires the ControlAdded event
///
/// Control that has been added to the collection
protected virtual void OnControlAdded(Control control) {
if(ControlAdded != null)
ControlAdded(this, new ControlEventArgs(control));
}
///
/// Called when a control has been removed to the collection,
/// fires the ControlRemoved event
///
/// Control that has been removed from the collection
protected virtual void OnControlRemoved(Control control) {
if(ControlRemoved != null)
ControlRemoved(this, new ControlEventArgs(control));
}
}
} // namespace Nuclex.Windows.Forms