基本信息
源码名称:c# winform 拖拽特效 例子源码
源码大小:0.35M
文件格式:.zip
开发语言:C#
更新时间:2014-12-16
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 6 元 
   源码介绍

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WinFormDragAndDrop
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //在listBox1添加项
            this.listBox1.Items.Add("项目一");
            this.listBox1.Items.Add("项目二");
            this.listBox1.Items.Add("项目三");
            this.listBox1.Items.Add("项目四");
            this.listBox1.Items.Add("项目五");

            //设置treeview的AllowDrop属性(允许放置属性)为true
            this.treeView1.AllowDrop = true;

            this.listBox1.MouseDown  = new MouseEventHandler(listBox1_MouseDown);
            this.treeView1.DragEnter  = new DragEventHandler(treeView1_DragEnter);
            this.treeView1.DragDrop  = new DragEventHandler(treeView1_DragDrop);
        }

        private void listBox1_MouseDown(object sender, MouseEventArgs e)
        {
            //调用DoDragDrop方法
            if (this.listBox1.SelectedItem != null)
            {
                this.listBox1.DoDragDrop(this.listBox1.SelectedItem, DragDropEffects.Copy);
            }
        }

        private void treeView1_DragEnter(object sender, DragEventArgs e)
        {
            //设置拖拽类型(这里是复制拖拽)
            e.Effect = DragDropEffects.Copy;
        }

        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            //获取值
            string item = (string)e.Data.GetData(e.Data.GetFormats()[0]);

            this.treeView1.Nodes.Add(item);
        }
    }
}