打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
拖动文本文档到richTextBox1中

拖动文本文档到richTextBox1中

  this.richTextBox1.DragEnter += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragEnter);
            this.richTextBox1.DragDrop += new System.Windows.Forms.DragEventHandler(this.richTextBox1_DragDrop);

   private void Form1_Load(object sender, EventArgs e)
        {//允许richTextBox1控件实现拖放操作
            this.richTextBox1.AllowDrop = true;
        }
        private void richTextBox1_DragEnter(object sender, DragEventArgs e)
        {//从拖动源复制数据,并将其滚动到放置目标中
          if(e.Data.GetDataPresent(DataFormats.FileDrop))
              e.Effect=DragDropEffects.All;
        }

        private void richTextBox1_DragDrop(object sender, DragEventArgs e)
        {//取得文本文件名并打开
            //可以使用DataFormats.FileDrop在拖放操作过程中与外壳程序文件的拖动操作进行交互
           if(e.Data.GetDataPresent(DataFormats.FileDrop))
           {
               string[] MyPathArray =(string[])e.Data.GetData(DataFormats.FileDrop) ;
               foreach (string MyPath in MyPathArray)
               {
                   this.richTextBox1.LoadFile(MyPath, RichTextBoxStreamType.PlainText);
               }
           }
        }

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
WinForm中拖动文件夹到窗口组件上记录路径
[C#]richtextbox实现拖放
vb.net入门——在 Windows 窗体中执行拖放操作
C# 实现控件拖动(DragDrop)功能简介
C#中的Clipboard与ContextMenuStrip应用举例
C#如何实现DataGridView到DataGridView的拖拽
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服