C#でFormを表示して ファイルのドロップを受け付けて
投げ込まれたもの(複数個なら最初の)が何だったのかをMessageBoxで表示します
以下のソースをcsc.exeに通すだけで出来ます(VisualStudioの環境は必須ではありません)
using A_Forms = System.Windows.Forms; using A_Application = System.Windows.Forms.Application; using A_DataFormats = System.Windows.Forms.DataFormats; using A_DragDropEffects = System.Windows.Forms.DragDropEffects; using A_DragEventArgs = System.Windows.Forms.DragEventArgs; using A_DragEventHandler = System.Windows.Forms.DragEventHandler; using A_FormBorderStyle = System.Windows.Forms.FormBorderStyle; using A_MessageBox = System.Windows.Forms.MessageBox; using A_Size = System.Drawing.Size; using A_EventArgs = System.EventArgs; using A_EventHandler = System.EventHandler; namespace AppFileDrop { public class Form1 : A_Forms.Form { public Form1() { this.Name = "Form1"; this.ClientSize = new A_Size(800, 600); this.FormBorderStyle = A_FormBorderStyle.FixedSingle; this.Load += new A_EventHandler(this.Form1_Load); this.AllowDrop = true; this.DragDrop += new A_DragEventHandler(this.Form1_DragDrop); this.DragEnter += new A_DragEventHandler(this.Form1_DragEnter); } private void Form1_Load(object sender, A_EventArgs e) { // Form1.Load event } private void Form1_DragDrop(object sender, A_DragEventArgs e) { string[] files = (string[])e.Data.GetData(A_DataFormats.FileDrop, false); A_MessageBox.Show(files[0]); } private void Form1_DragEnter(object sender, A_DragEventArgs e) { if (e.Data.GetDataPresent(A_DataFormats.FileDrop)) { e.Effect = A_DragDropEffects.Copy; } } [System.STAThread] static void Main() { A_Application.EnableVisualStyles(); A_Application.Run(new Form1()); } } }