VB.Net程序设计:拖放数据操作-从ListBox中拖放数据到ListBox 中

前端之家收集整理的这篇文章主要介绍了VB.Net程序设计:拖放数据操作-从ListBox中拖放数据到ListBox 中前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

VB.Net程序设计:从ListBox中拖放数据到ListBox 中。(VS2005)

运行界面图:

代码

PublicClassFrmList2List
DimiAsInteger

PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click
Me.Close()
EndSub


PrivateSubForm3_Load(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMe.Load
Fori=1To5
Me.ListBox1.Items.Add(i)
Next
Fori=6To9
Me.ListBox2.Items.Add(i)
Next
ListBox1.AllowDrop
=True
ListBox2.AllowDrop
=True
EndSub


PrivateSubListBox1_MouseDown(ByValsenderAsObject,ByValeAsSystem.Windows.Forms.MouseEventArgs)HandlesListBox1.MouseDown
Ife.Button=Windows.Forms.MouseButtons.LeftThen
IfListBox1.SelectedItemIsNotNothingThen
Me.ListBox1.DoDragDrop(Me.ListBox1.SelectedItem.ToString,DragDropEffects.Copy)
Me.Label1.Text="启动拖放数据..."&Me.ListBox1.SelectedItem
Else
Me.Label1.Text=""
EndIf
EndIf
EndSub


PrivateSubListBox2_DragEnter(ByValsenderAsSystem.Object,ByValeAsSystem.Windows.Forms.DragEventArgs)HandlesListBox2.DragEnter
If(e.Data.GetDataPresent(DataFormats.Text))Then
Me.Label1.Text="有数据拖进来...托..."
e.Effect
=DragDropEffects.Copy
Else
e.Effect
=DragDropEffects.None
Me.Label1.Text=""
EndIf
EndSub


PrivateSubListBox2_DragDrop(ByValsenderAsSystem.Object,ByValeAsSystem.Windows.Forms.DragEventArgs)HandlesListBox2.DragDrop
Ife.Data.GetDataPresent(DataFormats.Text)Then
Me.ListBox2.Items.Add(e.Data.GetData(DataFormats.Text))
Me.Label1.Text="有数据放进来...放..."
EndIf
EndSub


PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click
Me.Label1.Text=""
EndSub


PrivateSubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click
Me.ListBox1.ClearSelected()
EndSub


EndClass

原文链接:https://www.f2er.com/vb/263312.html

猜你在找的VB相关文章