private void Btn_Click(object sender, EventArgs e) { Guid index; Button button = (Button)sender; Guid.TryParse(button.Name, out index); CancellationTokenSource ts = (CancellationTokenSource)button.Tag; if (ts != null) { ts.Cancel(); } CustomProgressBar prB = null; Button btn = null; foreach (Control ctrl in groupBox2.Controls) { if (ctrl.Name.Equals($"{index}")) { btn = (Button)ctrl; btn.Click -= Btn_Click; } if (ctrl.Name.Equals($"progressBar{index}")) { prB = (CustomProgressBar)ctrl; } } if (prB != null && btn != null) { groupBox2.Controls.Remove(prB); groupBox2.Controls.Remove(btn); ReBuildControl(); } }
private void AddProgressBar(string url, CancellationTokenSource ts, Guid guid) { count++; int Y = count * 19; label_count.Text = $"count = {count}"; int progressX = 10; int buttonX = 474; Button btn = new Button() { BackColor = Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(0))))), Font = new Font("Microsoft Sans Serif", 9F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(204))), Location = new Point(buttonX, Y), Name = guid.ToString(), Size = new Size(31, 23), Text = "X", UseVisualStyleBackColor = false, Tag = ts }; btn.Click += Btn_Click; groupBox2.Controls.Add(btn); CustomProgressBar progressBar = new CustomProgressBar() { Location = new Point(progressX, Y), Name = $"progressBar{guid}", Size = new Size(458, 23), DisplayStyle = ProgressBarDisplayText.CustomText, CustomText = url }; progressBar.Value = 20; groupBox2.Controls.Add(progressBar); }