我想在单个 ListView 中拖放时显示一条蓝线。这应该有助于识别拖动的行是否会被放置在实际行之前或之后。 (其他需要的事件,如 .DragEnter、.DragDrop 正在按预期工作)。
如何在没有第 3 方 ListView 控件的情况下在 VB.NET 中绘制这样一条蓝线?
到目前为止,我找到了“GiveFeedback”事件:
Sub listView1_GiveFeedback(ByVal sender As Object, ByVal e As GiveFeedbackEventArgs) Handles listView1.GiveFeedback
e.UseDefaultCursors = False
Windows.Forms.Cursor.Current = Cursors.Cross
'<--- Show the blue insertion line until row is dropped
End Sub
有人可以告诉我蓝色插入行缺少的代码吗?
最佳答案
谢谢您为我指明了正确的方向!我在 .DragOver 事件中找到了所需的解决方案:
Sub ListView1_DragOver(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragOver
Dim MousePointerCoordinates As Point = ListView1.PointToClient(Cursor.Position)
Dim RowIndex As Integer = ListView1.InsertionMark.NearestIndex(MousePointerCoordinates)
ListView1.InsertionMark.Index = RowIndex
End Sub
线条本身的颜色在 form.load 中定义
ListView1.InsertionMark.Color = Color.Blue
关于vb.net - 在 ListView 中拖放时在行之前/之后插入一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19489514/