我使用过treeview 点击树节点(好友分组)的时候出现panel(好友列表) 后来panel会遮住其他的树节点
然后改成用label 点击label(好友分组)的时候出现panel(好友列表) 然后把没点到的label坐标下移到panel后面
现在老是出现label位移的错误,要么少了要么多了
panel的位移没有错...我的思路代码如下//新建个label数组
Label[] lblgroup = new Label[15];
//最开始的分组出现位置
Point plp = new Point(0,25);//在窗体读取的时候动态生成15个存分组信息的label
private void MainForm_Load(object sender, EventArgs e)
{
for (int i = 0; i < 15; i++)
{
lblgroup[i] = new Label();
lblgroup[i].AutoSize = false;
lblgroup[i].Text = i.ToString();
lblgroup[i].Location = pgp;
lblgroup[i].Height = 10;
lblgroup[i].BackColor =Color.Transparent;
//这是最外层装label的panel
lblgroup[i].Parent = pnlSuspendShowInfo;
lblgroup[i].Tag = i;
//给所有label共用一个点击事件
lblgroup[i].Click += new System.EventHandler(this.lblLever_Click);
pgp.Y += 23;
}
}
//当label被点击的时候触发
private void lblLever_Click(object sender, EventArgs e)
{
//获取当前点击的label
Label lbl = (Label)sender;
//判断panel将要在哪个label下出现
for (int i = 0; i < Convert.ToInt32(lbl.Tag); i++)
{
plp.Y += 20;
}
pnlSuspendShowInfo.Width = 285;
pnlSuspendShowInfo.Height = 365;
//循环创建10个panel(好友信息)
for (int i = 0; i < 10; i++)
{
Panel pl = new Panel();
pl.Parent = pnlSuspendShowInfo;
pl.BackColor = Color.Red;
pl.Width = 260;
pl.Height = 20;
pl.Location = plp; PictureBox pb = new PictureBox();
pb.Parent = pl;
pb.Width = 20;
pb.Height = 20;
pb.Location = pbp;
pb.BackgroundImage = img2.Images[i]; Label lb = new Label();
lb.Parent = pl;
lb.Width = 245;
lb.Height = 15;
lb.Location = plbp;
lb.Text = "桂雏菊"; plp.Y += 22;
}
b = true;
//遍历最外层panel的所有控件
foreach (Control item in pnlSuspendShowInfo.Controls)
{
//如果是label的话
if (item is Label)
{
//把当前点击的label下面的所有label坐标改变,上面的label不需要更改坐标
if (item.Text != lbl.Text&&Convert.ToInt32(item.Tag)>Convert.ToInt32(lbl.Tag))
{
for (int i = 0; i < Convert.ToInt32(item.Tag); i++)
{
item.Location = plp;
plp.Y += 20;
}
}
}
}
} 代码就是这样,老是错位...请各位大神帮帮忙...马上就要交作业了...
如果有更好的方法请留下您的足迹...谢谢
然后改成用label 点击label(好友分组)的时候出现panel(好友列表) 然后把没点到的label坐标下移到panel后面
现在老是出现label位移的错误,要么少了要么多了
panel的位移没有错...我的思路代码如下//新建个label数组
Label[] lblgroup = new Label[15];
//最开始的分组出现位置
Point plp = new Point(0,25);//在窗体读取的时候动态生成15个存分组信息的label
private void MainForm_Load(object sender, EventArgs e)
{
for (int i = 0; i < 15; i++)
{
lblgroup[i] = new Label();
lblgroup[i].AutoSize = false;
lblgroup[i].Text = i.ToString();
lblgroup[i].Location = pgp;
lblgroup[i].Height = 10;
lblgroup[i].BackColor =Color.Transparent;
//这是最外层装label的panel
lblgroup[i].Parent = pnlSuspendShowInfo;
lblgroup[i].Tag = i;
//给所有label共用一个点击事件
lblgroup[i].Click += new System.EventHandler(this.lblLever_Click);
pgp.Y += 23;
}
}
//当label被点击的时候触发
private void lblLever_Click(object sender, EventArgs e)
{
//获取当前点击的label
Label lbl = (Label)sender;
//判断panel将要在哪个label下出现
for (int i = 0; i < Convert.ToInt32(lbl.Tag); i++)
{
plp.Y += 20;
}
pnlSuspendShowInfo.Width = 285;
pnlSuspendShowInfo.Height = 365;
//循环创建10个panel(好友信息)
for (int i = 0; i < 10; i++)
{
Panel pl = new Panel();
pl.Parent = pnlSuspendShowInfo;
pl.BackColor = Color.Red;
pl.Width = 260;
pl.Height = 20;
pl.Location = plp; PictureBox pb = new PictureBox();
pb.Parent = pl;
pb.Width = 20;
pb.Height = 20;
pb.Location = pbp;
pb.BackgroundImage = img2.Images[i]; Label lb = new Label();
lb.Parent = pl;
lb.Width = 245;
lb.Height = 15;
lb.Location = plbp;
lb.Text = "桂雏菊"; plp.Y += 22;
}
b = true;
//遍历最外层panel的所有控件
foreach (Control item in pnlSuspendShowInfo.Controls)
{
//如果是label的话
if (item is Label)
{
//把当前点击的label下面的所有label坐标改变,上面的label不需要更改坐标
if (item.Text != lbl.Text&&Convert.ToInt32(item.Tag)>Convert.ToInt32(lbl.Tag))
{
for (int i = 0; i < Convert.ToInt32(item.Tag); i++)
{
item.Location = plp;
plp.Y += 20;
}
}
}
}
} 代码就是这样,老是错位...请各位大神帮帮忙...马上就要交作业了...
如果有更好的方法请留下您的足迹...谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货