怎样实现拖放,比如从左边的ListBox里拖一项到右边某个控件时,把拖动项的Text显示在某一控件上。看了点MSDN,没看懂,所以才问的。

解决方案 »

  1.   

            private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
            {
                TreeNode s = (TreeNode)e.Item;
                this.treeView1.DoDragDrop(s.Text, DragDropEffects.Move | DragDropEffects.Copy);
            }//拖拽treeView的项        private void listBox1_DragEnter(object sender, DragEventArgs e)
            {
                if (e.Data.GetDataPresent(DataFormats.Text))
                    e.Effect = DragDropEffects.Move;
            }//拖拽时鼠标进入listBox        private void listBox1_DragDrop(object sender, DragEventArgs e)
            {
                this.textBox2.Items.Add(e.Data.GetData(DataFormats.Text).ToString());
                e.Effect = DragDropEffects.Move;
            }//完成拖拽
    //这是把treeView的拖到listBox
    //你要的listBox拖到其他差不多
    //至于显示label.Text = e.Data.GetData(DataFormats.Text).ToString();//listBox还有个支持拖拽的属性AllowDrop要设为True