gpt4 book ai didi

vb.net - 如何从Spotify拖放到Winforms应用程序

转载 作者:行者123 更新时间:2023-12-04 10:18:09 24 4
gpt4 key购买 nike

如果有人将Spotify曲目从Spotify桌面应用程序拖放到Excel,则Excel会显示歌手和歌曲名称。

我有一个Winforms应用程序,我想在其中做同样的事情。
如果我将其拖放到这样的列表框中...。

Private Sub ListBox1_DragEnter(sender As Object, e As DragEventArgs) Handles ListBox1.DragEnter
ListBox1.Items.Add(e.Data.GetData(DataFormats.Text))
End sub


....它所做的只是显示Spotify曲目ID。
由于Excel并非旨在读取Spotify网址,因此数据必须位于拖放中。但是无论我选择哪种数据格式,我都只会获得ID。

最佳答案

Private Sub lstQueue_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles lstQueue.MouseDown

If (e.Button = MouseButtons.Right) Then

'clear previous selection
lstQueue.SelectedItems.Clear()

'highlight selected item
lstQueue.SelectedIndex = lstQueue.IndexFromPoint(e.X, e.Y)

'initiate movedown event for drag/drop
Dim ix As Integer = lstQueue.IndexFromPoint(e.Location)
If ix <> -1 Then
lstQueue.DoDragDrop(ix.ToString, DragDropEffects.Move)
End If

End If

End Sub

Private Sub lstQueue_DragEnter(sender As Object, e As DragEventArgs) Handles lstQueue.DragEnter

'make label visile for drag/drop
lblMoveLine.Visible = True

End Sub

Private Sub lstQueue_DragOver(ByVal sender As Object, ByVal e As DragEventArgs) Handles lstQueue.DragOver

'allow drag over for drag/drop
If e.Data.GetDataPresent(DataFormats.Text) Then
e.Effect = DragDropEffects.Move
Dim index = lstQueue.IndexFromPoint(lstQueue.PointToClient(New Point(e.X, e.Y)))
lblMoveLine.Top = (index - lstQueue.TopIndex) * lstQueue.ItemHeight
End If

End Sub

Private Sub lstQueue_DragLeave(sender As Object, e As System.EventArgs) Handles lstQueue.DragLeave

'hide label for drag/drop
lblMoveLine.Visible = False

End Sub

Private Sub lstQueue_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles lstQueue.DragDrop

'remove item and add in new location
If e.Data.GetDataPresent(DataFormats.Text) Then
Dim dix As Integer = CInt(e.Data.GetData(DataFormats.Text))
Dim ix As Integer = lstQueue.IndexFromPoint(lstQueue.PointToClient(New Point(e.X, e.Y)))
If ix <> -1 Then
Dim obj As Object = lstQueue.Items(dix)
lstQueue.Items.Remove(obj)
lstQueue.Items.Insert(ix, obj)
lstQueue.SelectedIndex = ix
End If
End If

lblMoveLine.Visible = False

End Sub

关于vb.net - 如何从Spotify拖放到Winforms应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54088115/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com