// dragdrop.cs using System; using System.Drawing; using System.WinForms; public class DragDrop : Form { private ListBox listbox1; protected void listbox1_DragEnter(object s, DragEventArgs e) { e.Effect = DragDropEffects.All; } protected void listbox1_DragDrop(object s, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { foreach (string fileName in (string[])e.Data.GetData(DataFormats.FileDrop)) { listbox1.Items.Add(fileName); } } } public DragDrop() { this.Size = new Size(340, 480); this.Text = "ドラッグ&ドロップ・サンプル"; this.listbox1 = new ListBox(); listbox1.Dock = DockStyle.Fill; listbox1.AllowDrop = true; listbox1.DragEnter += new DragEventHandler(listbox1_DragEnter); listbox1.DragDrop += new DragEventHandler(listbox1_DragDrop); this.Controls.Add(listbox1); } public static void Main() { Application.Run(new DragDrop()); } }