如何控制动态生成的Lable的位置
- C# code
foreach (DataRow dr in dtPage.Rows) { string displayName = dr["displayname"].ToString(); Label lbl = new Label(); lbl.Text = displayName; //lbl.Location = new Point(400, 400); CheckBox chb = new CheckBox(); if (dt.Select("displayname='" + displayName + "'").Count() > 0) { chb.Checked = true; } else { chb.Checked = false; } //chb.Location = new Point(500, 500); this.Controls.Add(lbl); this.Controls.Add(chb); }
从一个DataTable中取出页面值设置为lable的Text,然后看ListView中当前选中用户用哪些权限,如果有权限访问该页的话就将CheckBox设置为Checked。。因为页面(displayName字段)个数不止一个,所以要生成好多个Lable,如何控制他们的Location呢?像我这样写死位置的话,就都重在一起了。。。
[解决办法]
计算啊
比如
x+=60;
lbl.Location = new Point(x, y);
[解决办法]
- C# code
lbl.Dock = DockStyle.Top;