On Feb 7, 12:05*pm, "Griff" <GriffithsJ_...@htomail.comwrote:
What makes you think that the events do not appear to fire? Do you
have a debug.writeline in them?
Yes. *I have break-points (also tried message boxes etc). *I'm certainthe
events don't fire.
XAML for the text box is as follows:
<TextBox HorizontalContentAlignment="Left" Margin="146,13,12,0"
Name="txtFile" AllowDrop="True" Height="25" VerticalAlignment="Top">
<TextBox.BitmapEffect>
<OuterGlowBitmapEffect />
</TextBox.BitmapEffect>
</TextBox>
I only replied because I just recently figured out for the first time
how Drag and Drop works in .NET. I really can'y say why the event's
don't seem to be firing. You mention that you set the AllowDrop for
the TextBox, but are you sure you enabled it for the form as well?
Here is the working code from my application's form that makies use of
DragDrop when editing a SQL Query:
Private Sub txtQuery_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles txtQuery.DragEnter
Dim fi As FileInfo
Dim sFiles As String()
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
sFiles = CType(e.Data.GetData(DataFormats.FileDrop),
String())
fi = New FileInfo(sFiles(0))
If fi.Extension.ToUpper = ".SQL" Then
If sFiles.GetUpperBound(0) = 0 Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
Else
e.Effect = DragDropEffects.None
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub txtQuery_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles txtQuery.DragDrop
Dim myReader As StreamReader
Dim sFiles As String()
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
sFiles = CType(e.Data.GetData(DataFormats.FileDrop),
String())
myReader = New StreamReader(sFiles(0))
txtQuery.Text = myReader.ReadToEnd
myReader.Close()
End If
End Sub