Hi James,
|| The sample program did all sorts of fancy junk like dynamically create it's
|| user controls etc. (pomp - is it really necessary to be so gaudy when trying
|| to explain a simple point?) So, realizing the state of the economy and the
|| period of history in which I was so unfortunately born, I spent the next 3 or
|| so hours weeding through the affectatious displays of bravado and uselessly
|| flagrant manefestations of excess (blank lines every where in the sample code
|| - What does "CONCISE" mean?)
LOL. Do you mean the example given with Control.DoDragDrop? I agree -
it's horrendous. In my MSDN (2001) it's much, much shorter.
In your example, you start the Drag with MouseMove - this is going to start
a lot of drags. Surely it should be based on the mouse button being held down?
(And there's an assignment to dropEffects but this doesn't then get used.)
Your drag object is a string - the path of the last Node that the mouse moved over.
Would it not be better to drag the Node itself? This will allow better error checking.
That string could have been dragged from anywhere and may not be a Node path at all.
The Drag effect is continually being set in DragOver, but this need only be done once
in DragEnter. It would also be useful to check that the drag contents are the right type
so that the No-drag-here cursor can be displayed for the wrong type.
||
www.UCOM-ISM.com
That's a lot of reading. Probably some good stuff in it.
Regards,
Fergus
<code>
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As EventArgs) Handles MyBase.Load
'Set the AllowDrop property so that data can be dragged onto it.
RichTextBox1.AllowDrop = True
'Add code here to populate ListBox1 with paths to text files.
End Sub
Private Sub ListBox1_MouseDown(ByVal sender As Object, _
ByVal e As MouseEventArgs) Handles ListBox1.MouseDown
Dim Lb As ListBox
Dim Index As Integer
'Determine which item was selected.
Lb = sender
Index = Lb.IndexFromPoint (New Point(e.X, e.Y))
'Start a drag-and-drop operation with that item.
If Index >= 0 Then
Lb.DoDragDrop(Lb.Items(Index), DragDropEffects.Link)
End If
End Sub
Private Sub RichTextBox1_DragEnter(ByVal sender As Object, _
ByVal e As DragEventArgs) Handles RichTextBox1.DragEnter
If (e.Data.GetDataPresent("Text")) Then
'Allow copying of the data to the RichTextBox control.
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Overloads Sub RichTextBox1_DragDrop(ByVal sender As Object, _
ByVal e As DragEventArgs) Handles RichTextBox1.DragDrop
'Load the file into the control.
RichTextBox1.LoadFile(e.Data.GetData("Text"), _
RichTextBoxStreamType.RichText)
End Sub
</code>