Public Class Form1 Private dragStart As System.Drawing.Point? = Nothing
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Label1.Text = "ドラッグしてください" End Sub
Private Sub Label1_MouseDown(sender As Object, e As MouseEventArgs) Handles Label1.MouseDown dragStart = If(e.Button.HasFlag(MouseButtons.Left), e.Location, Nothing) End Sub Private Sub Label1_MouseUp(sender As Object, e As MouseEventArgs) Handles Label1.MouseUp dragStart = Nothing End Sub Private Sub Label1_MouseMove(sender As Object, e As MouseEventArgs) Handles Label1.MouseMove If dragStart.HasValue Then Dim moveRect As New Rectangle( dragStart.Value.X - SystemInformation.DragSize.Width \ 2, dragStart.Value.Y - SystemInformation.DragSize.Height \ 2, SystemInformation.DragSize.Width, SystemInformation.DragSize.Height) If moveRect.Contains(e.Location) Then Return 'まだドラッグを開始していない End If
Dim dragData As New DataObject(DataFormats.FileDrop, New String() {"C:\NUL"}) Dim de As DragDropEffects = Label1.DoDragDrop(dragData, DragDropEffects.Copy) If de = DragDropEffects.None Then Return 'ドラッグがキャンセルされた End If
'ドロップ先のマウス座標は得られたが、 'ここから対象フォルダーを調査できるか…? Dim pos = Cursor.Position
End If End Sub
End Class
以下、思い付きでつらつらと。(試していません)
(案1) AccessibleObjectFromPoint API を使って、 IAccessible インターフェイスからドロップ先を調査できないか?