标签:
对一个文本框添加拖拽功能:
private void txtFolder_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Link; this.txtFolder.Cursor = System.Windows.Forms.Cursors.Arrow;//指定鼠标形状 } else { e.Effect = DragDropEffects.None; } } private void txtFolder_DragDrop(object sender, DragEventArgs e) { //DataFormats 数据的格式,下有多个静态属性都为string型,除FileDrop格式外还有Bitmap,Text,WaveAudio等格式 string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); this.txtFolder.Text = path; this.txtFolder.Cursor = System.Windows.Forms.Cursors.IBeam; //还原鼠标形状 }
标签:
原文地址:http://www.cnblogs.com/lunawzh/p/5520369.html