今天在做textBox拖曳的功能,学到一点点
textBoxCmdName.AllowDrop = true; textBoxCmdName.DragDrop += new DragEventHandler(txt_ObjDragDrop); textBoxCmdName.DragEnter += new DragEventHandler(txt_ObjDragEnter);
private static void txt_ObjDragEnter(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Link; } private static void txt_ObjDragDrop(object sender, DragEventArgs e) { try { string FileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();//文件 System.Diagnostics.Process.Start("notepad", FileName); //((TextBox)sender).Text = File.ReadAllText(FileName, Encoding.Default); } catch (Exception er) { Console.Write(er.Message); } }