分享

拖动文本文档到richTextBox1中...

 tttff 2010-10-28

拖动文本文档到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);
               }
           }
        }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多