自己写的一个C#的折叠菜单,可能写的很麻烦。。。仿WINDOWS那种吧,点一个按钮就会隐藏显示下面的菜单,其他菜单不变,以上
//两个LIST用来放BUTTON和PANEL
List<Button> listbut = new List<Button>();
List<Panel> listpan = new List<Panel>();
//这里就不多写了
private void Form1_Load(object sender, EventArgs e)
{
button3.Top = 0;
panel3.Top = button3.Top + button3.Height;
button4.Top = panel3.Top + panel3.Height;
panel4.Visible = false;
button5.Top = button4.Top + button4.Height;
panel5.Visible = false;
listbut.Add(button3);
listbut.Add(button4);
listbut.Add(button5);
listpan.Add(panel3);
listpan.Add(panel4);
listpan.Add(panel5);
}
//实现折叠的方法
private void btnpanv(Button btn)
{
int num1 = int.Parse(btn.Name.Substring(6));//这里的裁剪根据按钮名字来写
foreach (Button bt in listbut)
{
int num2 = int.Parse(bt.Name.Substring(6));//这里的裁剪根据按钮名字来写
int top = 0;
foreach (Panel pl in listpan)
{
int pnum = int.Parse(pl.Name.Substring(5));这里的裁剪根据PANEL名字来写
if (num2 > pnum && num2 != 3)//此处的3是最上的按钮编号
{
if (pl.Visible == true)
{
top += this.button3.Height + pl.Height;
}
else
{
top += this.button3.Height;
}
}
else if (num2 == pnum)
{
if (num2 == num1)
{
if (pl.Visible == true)
{
pl.Visible = false;
}
else
{
pl.Visible = true;
}
}
pl.Top = top + bt.Height;
break;
}
}
bt.Top = top;
}
}
private void button3_Click(object sender, EventArgs e)
{
btnpanv(button3);
}
private void button4_Click(object sender, EventArgs e)
{
btnpanv(button4);
}
private void button5_Click(object sender, EventArgs e)
{
btnpanv(button5);
}