在文本框中拖动文件或文件夹? C# [英] drag files or folders in textbox? C#

查看:129
本文介绍了在文本框中拖动文件或文件夹? C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将文件或文件夹拖到文本框中?我想把文件夹名称放在那个非常的文本框中。 C#.NET

How do i drag files or folders into a textbox? i want to put the foldername in that very textbox. C# .NET

推荐答案

我在这个链接

  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      textBox1.AllowDrop = true;
      textBox1.DragEnter += new DragEventHandler(textBox1_DragEnter);
      textBox1.DragDrop += new DragEventHandler(textBox1_DragDrop);

    }

    private void textBox1_DragEnter(object sender, DragEventArgs e)
    {
      if (e.Data.GetDataPresent(DataFormats.FileDrop))
        e.Effects = DragDropEffects.Copy;
      else
        e.Effects = DragDropEffects.None; 
    }

    private void textBox1_DragDrop(object sender, DragEventArgs e)
    {
      string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);


    string s="";

    foreach (string File in FileList)
    s = s+ " "+ File ;
    textBox1.Text = s;
    }
  }

这篇关于在文本框中拖动文件或文件夹? C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆