QQ的主界面中好友列表使用什么控件实现的,涉及到哪些知识,如何用C#做,能给出提示吗,那位大侠给个思路或代
2个回答
展开全部
以下是最简单实现的方法,仅供参考学习,更多的可以自己找现成控(组)件:
private int num = 3;
private void Form1_Load(object sender, EventArgs e)
{
int b = 0;
int l = 0;
for (int i = 0; i < this.num; i++)
{
Button btn = new Button();
//btn.Dock = DockStyle.Top;
btn.Name = "btn" + i;
btn.Tag = i;
btn.Size = new Size(284, 23);
btn.Location = new Point(0, b);
btn.Text = i.ToString();
btn.Click += new EventHandler(btn_Click);
this.Controls.Add(btn);
b += (i > 0 ? 23 : 111);
ListBox lb = new ListBox();
//lb.Dock = DockStyle.Top;
lb.Name = "lb" + i;
lb.Tag = i;
//lb.Visible = (i == 0);
lb.Size = new Size(284, 88);
lb.Location = new Point(0, l + 23);
lb.Items.Add(i);
this.Controls.Add(lb);
l += 23;
}
}
protected void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
Control[] btn1 = this.Controls.Find("btn1", true);
if (btn1.Length > 0)
{
int y1 = (btn.Text.Equals("0") ? 111 : 23);
Button b1 = (Button)btn1[0];
b1.Location = new Point(0, y1);
}
Control[] btn2 = this.Controls.Find("btn2", true);
if (btn2.Length > 0)
{
int y2 = (btn.Text.Equals("2") ? 46 : 134);
Button b2 = (Button)btn2[0];
b2.Location = new Point(0, y2);
}
for (int i = 0; i < this.num; i++)
{
Control[] lb = this.Controls.Find("lb" + i, true);
if (lb.Length == 0) continue;
lb[0].Visible = (i.ToString().Equals(btn.Text));
}
}
private int num = 3;
private void Form1_Load(object sender, EventArgs e)
{
int b = 0;
int l = 0;
for (int i = 0; i < this.num; i++)
{
Button btn = new Button();
//btn.Dock = DockStyle.Top;
btn.Name = "btn" + i;
btn.Tag = i;
btn.Size = new Size(284, 23);
btn.Location = new Point(0, b);
btn.Text = i.ToString();
btn.Click += new EventHandler(btn_Click);
this.Controls.Add(btn);
b += (i > 0 ? 23 : 111);
ListBox lb = new ListBox();
//lb.Dock = DockStyle.Top;
lb.Name = "lb" + i;
lb.Tag = i;
//lb.Visible = (i == 0);
lb.Size = new Size(284, 88);
lb.Location = new Point(0, l + 23);
lb.Items.Add(i);
this.Controls.Add(lb);
l += 23;
}
}
protected void btn_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
Control[] btn1 = this.Controls.Find("btn1", true);
if (btn1.Length > 0)
{
int y1 = (btn.Text.Equals("0") ? 111 : 23);
Button b1 = (Button)btn1[0];
b1.Location = new Point(0, y1);
}
Control[] btn2 = this.Controls.Find("btn2", true);
if (btn2.Length > 0)
{
int y2 = (btn.Text.Equals("2") ? 46 : 134);
Button b2 = (Button)btn2[0];
b2.Location = new Point(0, y2);
}
for (int i = 0; i < this.num; i++)
{
Control[] lb = this.Controls.Find("lb" + i, true);
if (lb.Length == 0) continue;
lb[0].Visible = (i.ToString().Equals(btn.Text));
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询