1.AllowDrop属性要设置为True2.C#代码参考一下写法
#region dgvResult_DragDrop 拖拽完成时,读取文件名全路径 /// <summary> /// 拖拽完成时,读取文件名全路径 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvResult_DragDrop(object sender, DragEventArgs e) { //文件路径+文件名 label1.Text = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); } #endregion #region dgvResult_DragEnter 拖拽时,文件类型可用 /// <summary> /// 拖拽时,文件类型可用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dgvResult_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } #endregion
时间: 2024-12-29 11:45:54