c# - 在文本框中拖动文件或文件夹? C#

标签 c# .net drag-and-drop

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

最佳答案

我根据这个 link 编写了这段代码

  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# - 在文本框中拖动文件或文件夹? C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1370538/

相关文章:

c# - 简单的Excel创建不会打开文件已损坏

c# - Azure 服务总线 AutoDeleteOnIdle

ios - 从 TableView 拖放到 Swift 中的另一个 View

javascript - 如果可拖动元素在可放置边界之前拖动,如何解决 jQuery UI 可放置错误,其中 over/out 不会触发

C#:使用抽象类强制构造函数签名?

c# - 带/不带支持字段的二进制格式化程序和属性

c# - 如何在 c# 中对两个列表进行笛卡尔连接?

c# - 是否有 string.Join(string, string[]) 的 LINQ 等价物

.net - 如何手动计算 .Net 类的传出耦合 (Ce)?

jquery - 使用 jQuery 拖放的排序列表