private void TasksForm_Load(object sender, EventArgs e) { int i = 0; int j = 0; int k = 0; int m = 0; List <TaskModel> existTasks = GetTaskListOfURL(); if (existTasks.Count == 0 || existTasks == null) { return; } foreach (var task in existTasks) { long tick = DateTime.Now.Ticks; Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32)); int seed = ran.Next(0, 9); LabelWithCheck lbck = BuildLabel(task.Name, seed); lbck.Location = new System.Drawing.Point(13 + (88 * m), 20 + (32 * k)); URLTasks.Controls.Add(lbck); i++; j++; m = i % 4; k = j / 4; } }
/// <summary> /// 构造标签 /// </summary> /// <param name="name"></param> /// <returns></returns> private LabelWithCheck BuildLabel(string name, int color) { LabelWithCheck lbck = new LabelWithCheck(); lbck.LabelText = name; lbck.BackColor = Color.LightPink; lbck.ForeColor = Color.Black; lbck.BackColor = ColorTranslator.FromHtml(ColorConvertor(color)); lbck.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); lbck.Size = new System.Drawing.Size(74, 22); return(lbck); }
private void selectAll_Click(object sender, EventArgs e) { foreach (Control groupBox in this.Controls) { if (groupBox is GroupBox) { foreach (Control checkItem in groupBox.Controls) { if (checkItem is LabelWithCheck) { LabelWithCheck myCheckItem = (LabelWithCheck)checkItem; if (myCheckItem.Checked == false) { myCheckItem.Checked = true; Console.WriteLine(myCheckItem.CheckState); } } } } } }
/// <summary> /// 构造标签 /// </summary> /// <param name="name"></param> /// <returns></returns> private LabelWithCheck BuildLabel(string name, int color) { LabelWithCheck lbck = new LabelWithCheck(); lbck.LabelText = name; lbck.BackColor = Color.LightPink; lbck.ForeColor = Color.Black; lbck.BackColor = ColorTranslator.FromHtml(ColorConvertor(color)); lbck.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); lbck.Size = new System.Drawing.Size(74, 22); return lbck; }