using System;
using HashtableSystem.Collections.Hashtable;
using RectangleSystem.Drawing.Rectangle;
using ControlSystem.Windows.Forms.Control;
namespace LayoutManager{
public class QLayout : ILayoutManager {
public enum Direction:byte {Horizontal, Vertical};
Control con;
Direction dir;
public QLayout(Direction dir) {
this.Dir = dir;
}
public Direction Dir {
get {
return dir;
}
set {
if (value == Direction.Horizontal || value == Direction.Vertical) {
dir = value;
}
}
}
#region ILayoutMgr Members
public Control Control {
get {
return con;
}
set {
if (value != null && value != con) {
con = value;
}
}
}
public void DoLayout() {
int space;
if (Control != null && Control.Controls.Count > 0) {
if (dir == Direction.Horizontal) {
space = Control.ClientSize.Width / Control.Controls.Count;
for (int i = 0; i < Control.Controls.Count; ++i) {
Control.Controls[i].Bounds = new Rectangle(i * space, 0, space, Control.ClientSize.Height);
}
} else { // dir == Direction.Vertical
space = Control.ClientSize.Height / Control.Controls.Count;
for (int i = 0; i < Control.Controls.Count; ++i) {
Control.Controls[i].Bounds = new Rectangle(0, i * space, Control.ClientSize.Width, space);
}
}
}
}
public void ControlAdded(Control c) {
// Nothing to do
}
public void ControlRemoved(Control c) {
// Nothing to do
}
#endregion
}
}
|