zoukankan      html  css  js  c++  java
  • 使RichTextBox可以拖拽

    默认情况下,这个控件不支持拖拽,没有相应的事件。

    我们只需重写一下相应的事件就可以实现拖拽.

    public class RichTextBoxDemo : RichTextBox
        {
            
    public delegate void mDrag(DragEventArgs e);
            
    public event mDrag DragDrop;        

            
    public bool AllowDrag
            {
                
    get { return base.AllowDrop; }
                
    set { base.AllowDrop = value; }
            }

            
    //private string[] files;

            
    //public string[] Files
            
    //{
            
    //    get { return files; }            
            
    //}

            
    /// <summary>
            
    /// 拖拽
            
    /// </summary>
            
    /// <param name="drgevent"></param>
            protected override void OnDragDrop(DragEventArgs e)
            {
                
    base.OnDragDrop(e);
                
    //if (this.DragDrop != null)
                
    //{
                
    //    if (e.Data.GetDataPresent(DataFormats.FileDrop))
                
    //    {
                
    //        string[] fs = (string[])e.Data.GetData(DataFormats.FileDrop, true);
                
    //        this.files = fs;
                
    //        this.DragDrop(fs[0]);
                
    //    }
                
    //}

                
    if (this.DragDrop != null)
                {
                    
    this.DragDrop(e);
                }
            }

        }

    这样,类RichTextBoxDemo就可以进行拖拽了。

    应用:

    this.RichTextBoxDemo1.AllowDrag = true;
    this.RichTextBoxDemo1.DragDrop +=new RichTextBoxDemo1.mDrag(RichTextBoxDemo1_DragDrop);


    private void RichTextBoxDemo1_DragDrop(DragEventArgs e)
            {
                MessageBox.Show(((
    string[])e.Data.GetData(DataFormats.FileDrop, false))[0]);

            }


    作者:冰碟
    出处:http://www.cnblogs.com/icebutterfly/
    版权:本文版权归作者和博客园共有
    转载:欢迎转载,为了保存作者的创作热情,请按要求【转载】,谢谢
    要求:未经作者同意,必须保留此段声明;必须在文章中给出原文连接;否则必究法律责任

  • 相关阅读:
    LF 第三章 装饰器和迭代器相关
    Python 文件管理
    Python 强制类型转换
    安装模块
    LF 第三章
    pep8 Python编码规则
    Help on module pyclbr:
    Help on class timedelta in module datetime:
    Help on function meshgrid in module numpy.lib.function_base:
    Help on module matplotlib.cm in matplotlib:
  • 原文地址:https://www.cnblogs.com/icebutterfly/p/1432515.html
Copyright © 2011-2022 走看看