| vb基础 | vb实例教程 | api调用 | 控件使用 | 经验技巧 | 数据库操作 | 算法及技术 | vb源码下载 |
将一个列表中的项拖到另一个列表框 Here注释:s a way that you can let users drag items from one list and drop them in another one. Create two lists (lstDraggedItems, lstDroppedItems) and a text box (txtItem) in a form (frmTip). Put the following code in the load event of your form. Private Sub Form_Load() 注释: Set the visible property of txtItem to false txtItem.Visible = False 注释:Add items to list1 (lstDraggedItems) lstDraggedItems.AddItem "Apple" lstDraggedItems.AddItem "Orange" lstDraggedItems.AddItem "Grape" lstDraggedItems.AddItem "Banana" lstDraggedItems.AddItem "Lemon" 注释: End Sub In the mouseDown event of the list lstDraggedItems put the following code: Private Sub lstDraggedItems_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 注释: txtItem.Text = lstDraggedItems.Text txtItem.Top = Y + lstDraggedItems.Top txtItem.Left = X + lstDraggedItems.Left txtItem.Drag 注释: End Sub In the dragDrop event of the list lstDroppedItems put the following code: Private Sub lstDroppedItems_DragDrop(Source As Control, X As Single, Y As Single) 注释: If lstDraggedItems.ItemData(lstDraggedItems.ListIndex) = 9 Then Exit Sub End If 注释: To make sure that this item will not be selected again lstDraggedItems.ItemData(lstDraggedItems.ListIndex) = 9 lstDroppedItems.AddItem txtItem.Text 注释: End Sub Now you can drag items from lstDraggedItems and drop them in LstDroppedItems. Note that you cannot drag from the second list to the first. Also, the dragged item remains in the first list. You注释:ll have to address those limitations yourself |
||||