日期:2014-05-18 浏览次数:21014 次
//参考,2个listbox都绑定到下面的事件处理函数 private bool isLeftMouseButtonDown = false; private void listBox_DragDrop(object sender, DragEventArgs e) { ListBox destListBox = sender as ListBox; if (e.Data.GetDataPresent(typeof(ListBox))) { ListBox srcListBox = e.Data.GetData(typeof(ListBox)) as ListBox; destListBox.Items.Add(srcListBox.SelectedItem); srcListBox.Items.Remove(srcListBox.SelectedItem); } } private void listBox_DragEnter(object sender, DragEventArgs e) { e.Effect = e.AllowedEffect; } private void listBox_MouseDown(object sender, MouseEventArgs e) { isLeftMouseButtonDown = true; } private void listBox_MouseMove(object sender, MouseEventArgs e) { if (isLeftMouseButtonDown) { ListBox lb = sender as ListBox; if (lb.SelectedItem != null) { lb.DoDragDrop(lb, DragDropEffects.Move); } } } private void listBox_MouseUp(object sender, MouseEventArgs e) { isLeftMouseButtonDown = false; }
------解决方案--------------------
4楼的就可以。
不过:首先:使你的第二个listbox的AllowDrop属性设为真,使其可以接受拖放的数据。
------解决方案--------------------
向四楼学习.
------解决方案--------------------
isLeftMouseButtonDown 是什么啊!?
------解决方案--------------------
mark