using System.Windows.Forms;
using System.ComponentModel;
namespace LayoutManager{
public class LayoutPanel : Control {
protected ILayoutManager layoutMgr;
public LayoutPanel(ILayoutManager layoutMgr) {
Manager = layoutMgr;
this.Layout += new LayoutEventHandler(DoLayout);
this.ControlAdded += new ControlEventHandler(ContrAdd);
this.ControlRemoved += new ControlEventHandler(ContrRem);
}
public LayoutPanel() : this (null) { }
[Browsable(true)]
[ReadOnly(true)]
public LayoutManager.ILayoutManager Manager {
get {
return layoutMgr;
}
set {
if (value != null && value != layoutMgr) {
layoutMgr = value;
layoutMgr.Control = this;
foreach(Control c in Controls) {
layoutMgr.ControlAdded(c);
}
layoutMgr.DoLayout();
}
}
}
private void ContrAdd(object sender, ControlEventArgs e) {
layoutMgr.ControlAdded(e.Control);
}
private void ContrRem(object sender, ControlEventArgs e) {
layoutMgr.ControlRemoved(e.Control);
}
private void DoLayout(object sender, LayoutEventArgs e) {
layoutMgr.DoLayout();
}
}
}
|