private void PhotoItemCopy_MyCheckedChange(object sender, EventArgs e) { MyItemTemplate item = sender as MyItemTemplate; if (item.Checked) { MyCopyItem copyItem = new MyCopyItem(item); copyItem.ParentIndex = item.Index; copyItem.Checked = true; this.flowLayoutPanel4.Controls.Add(copyItem); copyItem.Index = this.flowLayoutPanel4.Controls.GetChildIndex(copyItem); copyItem.MyCheckedChange += CopyItem_MyCheckedChange; } else { if (item is MyItemTemplate) { foreach (MyCopyItem copyItem in flowLayoutPanel4.Controls) { if (copyItem.ParentIndex == item.Index) { this.flowLayoutPanel4.Controls.Remove(copyItem); } } return; } } }
private void CopyItem_MyCheckedChange(object sender, EventArgs e) { MyCopyItem copyItem = sender as MyCopyItem; if (!copyItem.Checked) { this.flowLayoutPanel4.Controls.Remove(copyItem); foreach (MyItemTemplate parentItem in flowLayoutPanel3.Controls) { if (parentItem.Index == copyItem.ParentIndex) { parentItem.Checked = false; } } } }