轻松实现控件间托拽操作 40Star(原作)
2024-07-21 02:24:18
供稿:网友
轻松实现控件间托拽操作 40star(原作)
在vb.net里实现listbox之间的托拽,首先要使接受托拽数据的控件的allowdrop属性设为真。再要处理的就是托拽效果,allowedeffect是设置托拽的源控件的动作效果,而effect是设置目标控件的动作。这些东东可以在drageventargs members中查到!
private sub form1_load(byval sender as system.object, byval e as system.eventargs) handles mybase.load
dim i as int32
for i = 0 to 9
listbox1.items.add("item " & i)
next
listbox2.allowdrop = true
end sub
private sub listbox1_mousedown(byval sender as object, byval e as system.windows.forms.mouseeventargs) handles listbox1.mousedown
dim itemindex as integer
itemindex = listbox1.indexfrompoint(e.x, e.y)
if itemindex >= 0 then
listbox1.dodragdrop(listbox1.items(itemindex), dragdropeffects.copy)
end if
end sub
private sub listbox2_dragenter(byval sender as object, byval e as system.windows.forms.drageventargs) handles listbox2.dragenter
if (e.data.getdatapresent(dataformats.text)) then
e.effect = dragdropeffects.copy
else
e.effect = dragdropeffects.none
end if
end sub
private sub listbox2_dragdrop(byval sender as object, byval e as system.windows.forms.drageventargs) handles listbox2.dragdrop
dim sitem as string
sitem = e.data.getdata(dataformats.text).tostring
listbox2.items.add(sitem)
listbox1.items.removeat(listbox1.findstring(sitem))
end sub