zoukankan      html  css  js  c++  java
  • RichTextBox的拖放功能DragDrop

    参考:http://blog.iordanov.info/?p=32

    实现RichTextBox的拖放功能只要设置EnableAutoDragDrop = true就自动实现了,非常简单。但是要实现一些个性化的控制,就有一点复杂了。

    我需要实现的是:如果拖放文件进来,不想默认的一样嵌入一个对象连接,而是把文件上传;其他情况就想默认一样。

    首先得设定AllowDrop = true;但是vs的控件的事件设定里面是没有DragEnter和DragDrop事件的,只能手工写代码。

       //添加事件
        private void AddRtb1Event()
            {
                rtb1.AllowDrop = true;
                
                rtb1.DragEnter += new DragEventHandler(rtb1_DragEnter);
                rtb1.DragDrop += new DragEventHandler(rtb1_DragDrop);
                
            }       
            private void rtb1_DragEnter(object sender, DragEventArgs e)
            {
                e.Effect = DragDropEffects.Copy  ;
                String[] supportedFormats = e.Data.GetFormats(true);
                if (supportedFormats != null)
                {
                    List<string> sfList = new List<string>(supportedFormats);
                    if (sfList.Contains(DataFormats.FileDrop.ToString()) )
                    {
                        rtb1.EnableAutoDragDrop = false;
                    }
                    else
                    {
                        rtb1.EnableAutoDragDrop = true;
    
                    }
                }
    
                
            }
    
            private void rtb1_DragDrop(object sender, DragEventArgs e)
            {
                String[] supportedFormats = e.Data.GetFormats(true);
                if (supportedFormats != null)
                {
                    List<string> sfList = new List<string>(supportedFormats);
                    if (sfList.Contains(DataFormats.FileDrop.ToString()))
                    {
                        string[] fileList = (string[])((System.Array)e.Data.GetData(DataFormats.FileDrop));
                        foreach (string fileName in fileList)
                        {
                            MessageBox.Show(fileName);
                        }
                    }
                }
                rtb1.EnableAutoDragDrop = true;
            }
    
        }
  • 相关阅读:
    hdu-4283 You Are the One 区间dp,
    HDU
    HDU
    HDU
    SPOJ
    UESTC
    CodeForces
    HDU
    Git中文书籍
    zeng studio的项目窗口PHP Explorer
  • 原文地址:https://www.cnblogs.com/eyye/p/2743065.html
Copyright © 2011-2022 走看看