在将项目从Listview拖动到PC桌面时,我使用了一个功能将光标更改为图标。当我直接从"浮动"拖动项目时,光标工作。窗口到桌面,但当我尝试从Listview中拖动它时,它会更改,它嵌入在另一个控件中(这是我的情况)。换句话说,当光标离开Listview并触摸我的表单上的另一个控件(例如Panel)时,我的光标会变为如下图所示:
在删除Item之前,我怎样才能获得同样的游标?到目前为止,这是我的代码:
Private Sub Listview1_ItemDrag(sender As Object, e As ItemDragEventArgs) Handles Listview1.ItemDrag
Dim Lview As System.Windows.Forms.ListView = DirectCast(sender, System.Windows.Forms.ListView)
Dim filecollection As New ArrayList
If Lview.SelectedItems.Count > 0 Then
For Each myItem In Lview.SelectedItems
If File.Exists(myItem.Tag.ToString) Then
filecollection.Add(myItem.Tag.ToString)
ElseIf Directory.Exists(myItem.Tag.ToString) Then
filecollection.Add(myItem.Tag.ToString)
End If
Next
Dim result = Lview.DoDragDrop(New DataObject(DataFormats.FileDrop, DirectCast(IzbraniPredmeti.ToArray(GetType(String)), String())), DragDropEffects.Copy)
If result = DragDropEffects.Copy Then
Me.Cursor = Cursors.Default
End If
End If
End Sub
Private Sub Listview1_GiveFeedback(sender As Object, e As GiveFeedbackEventArgs) Handles Listview1.GiveFeedback
e.UseDefaultCursors = False
Dim Lview As System.Windows.Forms.ListView = DirectCast(sender, System.Windows.Forms.ListView)
Dim img As New Bitmap(MyImageList.Images(CacheShellIcon(Lview.SelectedItems(0).Tag.ToString)))
Me.Cursor = my_functions.CreateCursor(img) 'function to create cursor
End Sub
Private Sub Listview1_DragOver(sender As Object, e As DragEventArgs) Handles Listview1.DragOver
Dim Lview As System.Windows.Forms.ListView = DirectCast(sender, System.Windows.Forms.ListView)
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
End If
End Sub