Vb.net 在拖动过程中显示文本(&A);滴

Vb.net 在拖动过程中显示文本(&A);滴,vb.net,winforms,drag-and-drop,Vb.net,Winforms,Drag And Drop,我们的PO希望显示在两个列表框之间拖动的文本。 我没有找到任何线索,如何在开箱即用的windows窗体上执行此操作。 我找到了这篇文章,但它在表单上有一个额外的标签。这真的是最好的也是唯一的选择吗?根据我上面的评论,有一个关于的例子,除了在搜索中能够找到它之外,我不能获得任何荣誉,所有荣誉都归功于Elkay on Code Project 下面是复制和粘贴的代码,以防将来链接中断 Dim myCursor As TextCursor.xCursor = New TextCursor.xCurso

我们的PO希望显示在两个列表框之间拖动的文本。 我没有找到任何线索,如何在开箱即用的windows窗体上执行此操作。
我找到了这篇文章,但它在表单上有一个额外的标签。这真的是最好的也是唯一的选择吗?

根据我上面的评论,有一个关于的例子,除了在搜索中能够找到它之外,我不能获得任何荣誉,所有荣誉都归功于Elkay on Code Project

下面是复制和粘贴的代码,以防将来链接中断

Dim myCursor As TextCursor.xCursor = New TextCursor.xCursor
myCursor.CursorText = "This is a test cursor"
Me.Cursor = myCursor.GetCursor
Private _Dragging As Boolean        ' Indicates that Dragging has begun
Private _DragSource As Integer = 0      ' The source of the drag

' Here's my custom cursor
Private myCursor As TextCursor.xCursor = New TextCursor.xCursor

''' <summary>
''' Begin our Dragging - setup a few cursor properties
''' </summary>
Private Sub DragLabel_MouseDown(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) Handles DragLabel.MouseDown
    _Dragging = True

    myCursor.Shrinkage = 1
    myCursor.Fade = True
    myCursor.Font = DragLabel.Font
    myCursor.CursorText = DragLabel.Text

End Sub

''' <summary>
''' If dragging has begun, fire off the dragdrop and stuff the Object
''' </summary>
Private Sub DragLabel_MouseMove(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.MouseEventArgs) Handles DragLabel.MouseMove
    If _Dragging Then
        _DragSource = 1
        DragLabel.DoDragDrop(DragLabel.Text, DragDropEffects.Copy)
    End If
    _Dragging = False
End Sub

''' <summary>
''' If you don't do this, you'll get the standard "You can't drop here" cursor
''' </summary>
Private Sub DragLabel_DragOver(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DragEventArgs) Handles DragLabel.DragOver
    If e.Data.GetDataPresent(DataFormats.StringFormat) Then
        e.Effect = DragDropEffects.None
    End If
End Sub

''' <summary>
''' This bad boy is DragDrop UI's Golden Child.  
''' This will fire during the dragging operation
''' (once the DoDragDrop method has been started) and allow you to trap while dragging
'''
''' In the case of this Demo - I'm checking to see if we have a valid drop location:
''' we'll have both an effect AND a true Copy condition set.
''' </summary>
Private Sub DragLabel_GiveFeedback(ByVal sender As Object, _
  ByVal e As System.Windows.Forms.GiveFeedbackEventArgs) Handles DragLabel.GiveFeedback
    e.UseDefaultCursors = False
    If ((e.Effect And DragDropEffects.Copy) = DragDropEffects.Copy) Then
        myCursor.GoodDrop = TextCursors.xCursor.DropValid.GoodDrop
        Cursor.Current = myCursor.GetCursor
    Else
        myCursor.GoodDrop = TextCursors.xCursor.DropValid.BadDrop
        Cursor.Current = myCursor.GetCursor
    End If
End Sub

''' <summary>
''' Let the ap know we're over a good drop location
''' Share that knowledge with the User by changing our Drag Cursor and 
''' alter the drop control's bg color
''' </summary>
Private Sub DropLabel_DragOver(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DragEventArgs) Handles DropLabel.DragOver
    If e.Data.GetDataPresent(DataFormats.StringFormat) Then
        e.Effect = DragDropEffects.Copy
    End If
End Sub

''' <summary>
''' Perform the drop - if anyone knows a more intelligent way to determine 
''' WHERE the drag CAME FROM
''' I would love to hear about it!
''' </summary>
Private Sub DropLabel_DragDrop(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DragEventArgs) Handles DropLabel.DragDrop
    If (e.Data.GetDataPresent(GetType(System.String))) Then
        Dim item As Object = CType(e.Data.GetData(GetType(System.String)), _
                                System.Object)
        If _DragSource = 2 Then
            DropLabel.Font = AnotherDrag.Font
        Else
            DropLabel.Font = DragLabel.Font
        End If
        DropLabel.Text = item.ToString
    End If
End Sub
Dim myCursor As TextCursor.xCursor=New TextCursor.xCursor
myCursor.CursorText=“这是一个测试光标”
Me.Cursor=myCursor.GetCursor
私有(拖动为布尔值)表示已开始拖动
Private _dragsourceas Integer=0'拖动源
'这是我的自定义光标
Private myCursor As TextCursor.xCursor=新建TextCursor.xCursor
''' 
''开始拖动-设置一些光标属性
''' 
私有子DragLabel_MouseDown(ByVal发送方作为对象_
ByVal e作为System.Windows.Forms.MouseEventArgs)处理DragLabel.MouseDown
_拖动=真
myCursor.contraction=1
myCursor.Fade=True
myCursor.Font=DragLabel.Font
myCursor.CursorText=DragLabel.Text
端接头
''' 
''如果拖动已经开始,发射dragdrop并填充对象
''' 
私有子DragLabel_MouseMove(ByVal发送方作为对象_
ByVal e作为System.Windows.Forms.MouseEventArgs)处理DragLabel.MouseMove
如果,那么
_DragSource=1
DragLabel.DoDragDrop(DragLabel.Text,DragDropEffects.Copy)
如果结束
_拖动=错误
端接头
''' 
''如果你不这样做,你会得到标准的“你不能放在这里”光标
''' 
专用子DragLabel_DragOver(ByVal发送方作为对象_
ByVal e作为System.Windows.Forms.DragEventArgs)处理DragLabel.DragOver
如果e.Data.GetDataPresent(DataFormats.StringFormat),则
e、 效果=DragDropEffects。无
如果结束
端接头
''' 
''这个坏男孩是德拉格德罗普的金童。
''这将在拖动操作期间触发
''(一旦DoDragDrop方法启动)并允许您在拖动时陷阱
'''
''在本演示中-我正在检查我们是否有有效的放置位置:
''我们将设置效果和真实复制条件。
''' 
私有子DragLabel_GiveFeedback(ByVal发送方作为对象_
ByVal e作为System.Windows.Forms.GiveFeedbackEventArgs)处理DragLabel.GiveFeedback
e、 UseDefaultCursors=False
如果((e.Effect和DragDropEffects.Copy)=DragDropEffects.Copy),则
myCursor.GoodDrop=TextCursors.xCursor.DropValid.GoodDrop
Cursor.Current=myCursor.GetCursor
其他的
myCursor.GoodDrop=TextCursors.xCursor.DropValid.BadDrop
Cursor.Current=myCursor.GetCursor
如果结束
端接头
''' 
''让美联社知道我们在一个好的降落地点
''通过更改拖动光标和
''更改放置控件的背景颜色
''' 
专用子DropLabel_DragOver(ByVal发送方作为对象_
ByVal e作为System.Windows.Forms.DragEventArgs)处理DropLabel.Dragver
如果e.Data.GetDataPresent(DataFormats.StringFormat),则
e、 效果=DragDropEffects.Copy
如果结束
端接头
''' 
''执行下降-如果有人知道更聪明的方法来确定
''阻力来自哪里
''我很想听到这件事!
''' 
专用子DragDrop标签(ByVal发送器作为对象_
ByVal e作为System.Windows.Forms.DragEventArgs)处理DropLabel.DragDrop
如果(e.Data.GetDataPresent(GetType(System.String)),那么
作为对象的Dim项=CType(e.Data.GetData(GetType(System.String))_
系统(对象)
如果_DragSource=2,则
DropLabel.Font=另一个drag.Font
其他的
DropLabel.Font=DragLabel.Font
如果结束
DropLabel.Text=item.ToString
如果结束
端接头

论坛中的前两个答案都没有使用标签,他们只使用了
SelectedItem.ToString
?DragMessage对象是一个标签控件。从未尝试过它,因此出现了注释而不是答案,但是有一篇文章在上面。哦,我的糟糕,错过了这一点。这是一个非常简单而有效的方法-这样做有什么不对?@OSKM:谢谢,它很有效,所以你可以把它作为答案:)但我仍然不能相信这一定如此复杂。我会把它作为一个答案,因为它确实是,它承诺了什么,但这个解决方案有一个意想不到的副作用:我的列表框,这是源代码,在拖放后表现奇怪:滚动后列表不会重新绘制。滚动条工作,我仍然可以向下,选择,拖放最后一个项目(并在拖动过程中看到标题),但我看不到滚动项目和列表中的选择。