Code Snippet:
private void Form1_Load(object sender, EventArgs e)
{
//重整大小。
foreach (Control c in panel1.Controls)
{
//設定 Dock 配置。
c.Dock = DockStyle.Top;
//設定高度等於Button高度。
c.Size = c.Controls[0].Size;
//設定 Button Dock 配置。
c.Controls[0].Dock = DockStyle.Top;
}
//預設展開第一個。
PaintButtonPanel(button1);
}
private static void PaintButtonPanel(object sender)
{
if (sender is Control)
{
//Control。
Control c = sender as Control; //Button
c.Dock = DockStyle.Top;
//c 的父容器 Control。
Control cc = c.Parent as Control; //Panel
//cc 的父容器 Control。
Control ccc = cc.Parent as Control; //Panel
//這邊高度微調值設 4。
int x = 4;
foreach (Control i in ccc.Controls)
{
if (i != cc)
{
i.Height = c.Height;
x += i.Height;
}
}
//變動控制項高度。
cc.Height = ccc.Height - x;
}
}
private void button1_Click(object sender, EventArgs e)
{
PaintButtonPanel(sender);
}
private void button2_Click(object sender, EventArgs e)
{
PaintButtonPanel(sender);
}
private void button3_Click(object sender, EventArgs e)
{
PaintButtonPanel(sender);
}
private void button4_Click(object sender, EventArgs e)
{
PaintButtonPanel(sender);
}
private void button5_Click(object sender, EventArgs e)
{
PaintButtonPanel(sender);
}
沒有留言:
張貼留言