This works well:
Code:
Private Sub txtSI_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs _
) Handles txtSI.DragDrop
If (e.Data.GetDataPresent(DataFormats.Text)) Then _
txtSI.Text = e.Data.GetData(DataFormats.Text).ToString()
End Sub
Private Sub txtSI_DragEnter(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs _
) Handles txtSI.DragEnter
If (e.Data.GetDataPresent(DataFormats.Text)) Then
e.Effect = DragDropEffects.Copy
End Sub
Apparently during a drag operation, tere can be a variety of formats all available at the same time. This is why you cna drag from word (formatted text) into an email message that is plain text type. When Word/excel/Internet Explorer/whatever) is used as a source for a drag/drop operation, a rendering as text is created (if possible), one as RichText Format (if possible), and so on. So if gragging a section of a picture from Paint, no Text format would be present.
So the dragenter event can look to see if data of a particular format is present, and modify the cursor in accordance with whether you plan to be able to handle the format(s) that are present.
Accordingly, the dragDrop can make choices as to whether one of the formats present will be handled, as well as
which will be used if there are more than one that can be handled.
So for instance (again, in Word), if you are dropping from a source that incluedes Text and File, Word can decide whether to insert the text, a link to the file, or the contents of the file. (I haven't tried this, so I don't know which would be the case.)
In the same way you can program your own applications to hendle that which you want it to handle. (You can create your own format identifiers, and write the code to process that datatype. So if you create a complex object called clsPhotoShoot, you could create a data type identifier -- a string -- to indicate that this type of object is being dragged, and you could look for that identifier where the dropping is taking place, and write a case to handle it. I saw a scheduling program for a Dr.âs office that allowed dragging a clientâs appointments around on a calendar. That's just one example.)