VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > C#教程 >
  • c#拖放技术的典型应用

制作者:剑锋冷月 单位:无忧统计网,www.51stat.net
 

  在应用程序中,有时用户希望将数据从一个控件中拖到另一个控件中,此时就需要用到拖放技术。

  程序开发步骤:

  (1)新建一个窗体,在窗体中添加两个Label控件和两个TextBox控件,并将两个TextBox控件分别命名为txtDataTart和txtScoure。

  (2)将txtDataTart文本框的AllowDrop属性设置为true。

  (3)程序主要代码如下。

  private void txtDataTart_DragDrop(object sender, DragEventArgs e)
    {
      txtDataTart.Text = e.Data.GetData(DataFormats.Text).ToString();
    }
    private void txtDataTart_DragEnter(object sender, DragEventArgs e)
    {
      e.Effect = DragDropEffects.Copy;
    }
    private void txtScoure_MouseMove(object sender, MouseEventArgs e)
    {
      if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
      {
          string reportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,
           Application.StartupPath.LastIndexOf("")).LastIndexOf(""));
          reportPath += @"sl3293dwarro.cur";
          MyNoDropCursor = new Cursor(reportPath);
          DragDropEffects dropEffect = this.txtScoure.DoDragDrop(this.txtScoure.Text, DragDropEffects.Copy | DragDropEffects.Link);
      }    }



相关教程