winform实现拖动文件到窗体上的方法

论坛 期权论坛 脚本     
niminba   2021-5-23 02:29   403   0

本文实例讲述了winform实现拖动文件到窗体上的方法。分享给大家供大家参考。具体如下:

private void Form5_Load(object sender, EventArgs e)
{
 this.AllowDrop=true;
}
private void Form5_DragEnter(object sender, DragEventArgs e)
{
 if (e.Data.GetDataPresent(DataFormats.FileDrop))
 {
  string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
  foreach (string f in files)
  {
   listBox1.Items.Add(f);
  }
 }
}

希望本文所述对大家的C#程序设计有所帮助。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP