标签:
文件拖过来的代码为:
(System.Array)e.Data.GetData(DataFormats.FileDrop)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Security.Cryptography; namespace WindowsFormsApplication1 { public partial class MD5 : Form { public MD5() { InitializeComponent(); } private void MD5_Load(object sender, EventArgs e) { SetCtrlDrag.SetCtrlDragEvent(this.textBox1); } } public class SetCtrlDrag { public static void SetCtrlDragEvent(Control ctrl) { if (ctrl is TextBox) { TextBox tb = ctrl as TextBox; tb.AllowDrop = true; tb.DragEnter += (sender, e) => { e.Effect = DragDropEffects.Link;//拖动时的图标 }; tb.DragDrop += (sender, e) => { ((TextBox)sender).Text = "文件路径:"+((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); }; } } } }
标签:
原文地址:http://www.cnblogs.com/qh123/p/4329796.html