VB.Net程序设计:从ListBox中拖放数据到ListBox 中。(VS2005)
运行界面图:
代码:
PublicClassFrmList2ListClassFrmList2List DimiAsInteger
PrivateSubButton1_Click()SubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click Me.Close() EndSub
PrivateSubForm3_Load()SubForm3_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()SubListBox1_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()SubListBox2_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()SubListBox2_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()SubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click Me.Label1.Text="" EndSub
PrivateSubButton3_Click()SubButton3_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton3.Click Me.ListBox1.ClearSelected() EndSub
EndClass (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|