private void listBox1_MouseDown(object sender, MouseEventArgs e) { //调用DoDragDrop方法 if (this.listBox1.SelectedItem != null) { this.listBox1.DoDragDrop(this.listBox1.SelectedItem, DragDropEffects.Copy); } }
//设置treeview的AllowDrop属性(允许放置属性)为true this.treeView1.AllowDrop = true;
private void textBox1_DragEnter(object sender, DragEventArgs e) { //设置拖拽类型(这里是复制拖拽) e.Effect = DragDropEffects.Copy; } private void textBox1_DragDrop(object sender, DragEventArgs e) { //获取值 TableInfo item2 = (TableInfo)e.Data.GetData(typeof(TableInfo)); this.textBox1.AppendText(" "); this.textBox1.AppendText(item2.TableName); // MessageBox.Show(item2.TableName); }