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;
            }
    
        }
  • 相关阅读:
    android中src和background区别
    html标签大全
    android横竖屏切换时activity的生命周期
    onInterceptTouchEvent和onTouchEvent调用时序
    Android Activity单例
    Android dispatchTouchEvent
    android 2D API相关
    杭电 1085 Holding BinLaden Captive!
    杭电 1715 大菲波数
    杭电 1492 The number of divisors(约数) about Humble Numbers
  • 原文地址:https://www.cnblogs.com/eyye/p/2743065.html
Copyright © 2011-2022 走看看