void Form1_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); foreach (string file in files) { DownloadList.Add_to_List(file); } List <Label> lbls = FileTabPage.Controls.OfType <Label>().ToList(); foreach (Label lbl in lbls) { FileTabPage.Controls.Remove(lbl); } List <Button> btns = FileTabPage.Controls.OfType <Button>().ToList(); foreach (Button btn in btns) { if (btn.Text != "Add") { FileTabPage.Controls.Remove(btn); } } int x = 0; int y = 25; foreach (String file in DownloadList.download_list) { int index = DownloadList.Get_File_Index(file); String[] fileDirectories = file.Split('\\'); String Filename = fileDirectories[fileDirectories.Length - 1]; Label label = new Label { Size = new Size(266, 23), Location = new Point(x, y), Text = index + " : " + Filename, TextAlign = ContentAlignment.MiddleLeft, BackColor = Color.GreenYellow }; Button btn = new Button { Size = new Size(20, 23), Location = new Point(266, y), Text = "X", FlatStyle = FlatStyle.Popup, BackColor = Color.OrangeRed }; FileTabPage.Controls.Add(label); FileTabPage.Controls.Add(btn); btn.Click += (object s, EventArgs ev) => { DownloadList.Remove_By_Index(index); FileTabPage.Controls.Remove(label); FileTabPage.Controls.Remove(btn); lbls = FileTabPage.Controls.OfType <Label>().ToList(); foreach (Label lbl in lbls) { if (lbl.TabIndex > label.TabIndex) { lbl.Location = new Point(x, lbl.Location.Y - 25); string[] text = lbl.Text.Split(':'); int idx = Convert.ToInt32(text[0]); lbl.Text = idx - 1 + " : " + text[1]; } } btns = FileTabPage.Controls.OfType <Button>().ToList(); foreach (Button button in btns) { if (button.Text != "Add") { if (button.TabIndex > btn.TabIndex) { button.Location = new Point(266, button.Location.Y - 25); } } } }; y += 25; FileTabPage.AutoScroll = true; } }
private void AddFileButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = "F:\\"; openFileDialog.Filter = "All files (*.*)|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) { String File_Path = openFileDialog.FileName; FilesTextBox.Text = File_Path; DownloadList.Add_to_List(File_Path); List <Label> lbls = FileTabPage.Controls.OfType <Label>().ToList(); foreach (Label lbl in lbls) { FileTabPage.Controls.Remove(lbl); } List <Button> btns = FileTabPage.Controls.OfType <Button>().ToList(); foreach (Button btn in btns) { if (btn.Text != "Add") { FileTabPage.Controls.Remove(btn); } } int x = 0; int y = 25; foreach (String file in DownloadList.download_list) { int index = DownloadList.Get_File_Index(file); String[] fileDirectories = file.Split('\\'); String Filename = fileDirectories[fileDirectories.Length - 1]; Label label = new Label { Size = new Size(266, 23), Location = new Point(x, y), Text = index + " : " + Filename, TextAlign = ContentAlignment.MiddleLeft, BackColor = Color.GreenYellow }; Button btn = new Button { Size = new Size(20, 23), Location = new Point(266, y), Text = "X", FlatStyle = FlatStyle.Popup, BackColor = Color.OrangeRed }; FileTabPage.Controls.Add(label); FileTabPage.Controls.Add(btn); btn.Click += (object s, EventArgs ev) => { DownloadList.Remove_By_Index(index); FileTabPage.Controls.Remove(label); FileTabPage.Controls.Remove(btn); lbls = FileTabPage.Controls.OfType <Label>().ToList(); foreach (Label lbl in lbls) { if (lbl.TabIndex > label.TabIndex) { lbl.Location = new Point(x, lbl.Location.Y - 25); string[] text = lbl.Text.Split(':'); int idx = Convert.ToInt32(text[0]); lbl.Text = idx - 1 + " : " + text[1]; } } btns = FileTabPage.Controls.OfType <Button>().ToList(); foreach (Button button in btns) { if (button.Text != "Add") { if (button.TabIndex > btn.TabIndex) { button.Location = new Point(266, button.Location.Y - 25); } } } }; y += 25; FileTabPage.AutoScroll = true; } } }//EOF AddFileButton_Click