
效果图:
代码:
//分页或者多次加载时,需要删除之前产生的lable等控件
for (int tabID = ; tabID < ; tabID++)
{
foreach (Control control in this.tableLayoutPanel2.Controls)
{ // 遍历所有TextBox...
if (control is PictureBox)
{
PictureBox t = (PictureBox)control;
if (control.TabIndex == tabID)
{
if (tabID > list.Count - )
{
for (int i = tabID; i < ; i++)
{
//this.tableLayoutPanel2.Controls.Remove(control);
t.ImageLocation = null;
t.Controls.Remove(t.Controls[tabID.ToString()]);
string d = ("NO" + tabID.ToString());
t.Controls.Remove(t.Controls[d]);
t.Tag = -;
}
break;
} t.ImageLocation = list[tabID].VehicleImage;
t.Tag = (list[tabID].Id).ToString();
string m = ("NO" + tabID.ToString());
t.Controls.Remove(t.Controls[tabID.ToString()]);
t.Controls.Remove(t.Controls[m]);
Label C = new Label();
C.Parent = t;
C.Width = ;
C.Text = list[tabID].VehicleNumber;
C.Font = new Font("", );
C.ForeColor = Color.Black; C.Dock = DockStyle.Top;
C.BackColor = Color.Transparent;
C.TextAlign = ContentAlignment.TopLeft;
C.AutoSize = false;
C.Name = "NO" + tabID.ToString(); Label B = new Label();
B.Parent = t;
B.Width = ;
B.Text = list[tabID].VehicleZT;
B.Font = new Font("", );
switch (list[tabID].VehicleZT) {
case "待派":
B.ForeColor = Color.Blue;
break;
case "已派":
B.ForeColor = Color.Green;
break;
case "维修":
B.ForeColor = Color.Yellow ;
break;
case "停驶":
B.ForeColor = Color.Red;
break;
}
B.Dock = DockStyle.Bottom;
B.BackColor = Color.Transparent;
B.TextAlign = ContentAlignment.BottomRight;
B.AutoSize = false;
B.Name = tabID.ToString();
}
}
}
}