using System.Drawing;
using System.Windows.Forms;
namespace MainForm.Core {
public class HorizontalPanel : System.Windows.Forms.Panel {
public HorizontalPanel() {
Width = 0;
Height = 1;
AutoSize = true;
AutoScroll = false;
}
public HorizontalPanel(bool AutoScroll) {
Width = 0;
Height = 1;
AutoSize = !AutoScroll;
this.AutoScroll = AutoScroll;
}
int x = 0;
int h = 0;
public void add(Control control, int split) {
h = split;
//x = (x == 0) ? 0 : x += split;
HorizontalScroll.Enabled = true;
control.Location = getLocation();// new Point(x, 0);
Controls.Add(control);
x += control.Width;
if (x > Width && this.AutoScroll == true) {
Height = control.Height + 20;
} else {
Height = control.Height;
}
}
Point getLocation() {
x = (x == 0) ? 0 : x += h;
return new Point(x, 0);
}
public void add(Control control) {
add(control, 0);
}
protected override void OnControlRemoved(ControlEventArgs e) {
x = 0;
foreach (Control c in Controls) {
c.Location = getLocation();
x += c.Width;
}
}
}
}
No comments:
Post a Comment