zoukankan      html  css  js  c++  java
  • C# 拖拽事件

    实现一个textBox像另一个TextBox拖拽数据。

    一个控件想要被拖入数据的前提是AllowDrop属性为true。

    所以,首先需要将被拖入数据的textBox的AllowDrop属性设置为True;

    txt1为原textBox名称,txt2为要拖入数据的TextBox名称。

    代码如下:

    private void txt_DragDrop(object sender, DragEventArgs e)
    {
          string hit = (string)e.Data.GetData(typeof(string));
         txt.Text = hit;
    }

    private void txt_DragEnter(object sender, DragEventArgs e)
    {
       if (e.Data.GetDataPresent(typeof(string)))
      {
         e.Effect = DragDropEffects.Copy;
      }
      else
      {
          e.Effect = DragDropEffects.None;
      }
    }


    private void txt1_MouseDown(object sender, MouseEventArgs e)
    {
       if (txt1.Text.Trim() != "")
      {
        string s = txt1.Text;
        txt1.DoDragDrop(s, DragDropEffects.Copy);
     }
    }

    过去已逝,未来太远,只争今朝
  • 相关阅读:
    A
    B
    C
    I
    公共最大字串长度
    docker run 的背后的故事(zz)
    python之多并发socket(zz)
    Python垃圾回收机制:gc模块(zz)
    我要做的git的分享(zz)
    SpringMVC框架入门配置 IDEA下搭建Maven项目(zz)
  • 原文地址:https://www.cnblogs.com/BlogLwc/p/7784970.html
Copyright © 2011-2022 走看看