I have a drag and drop problem I cannot find a solution for. I want to allow the user to drop a text file onto a richtextbox but its being blocked somehow. I have VS2017 and Windows 10. UAC=NONE and I am the Admin of the PC. AllowDrop=True on the Form properties and EnableAutoDragDrop=True is on the Richtextbox properties.
I also tried adding
Me.AllowDrop = True
Me.RichTextBox1.AllowDrop = True
to the Form1_Load but that had no effect.
When I drag a text file over the form as soon as it reaches the form the cursor changes to a "NOT" symbol and if I drop the file the DragDrop event doesn't fire but the DragEnter event does fire when the drag reaches the richtextbox control. But the DragEnter event always goes to the ELSE stament even if the file is a text file. Its as if some security is blocking VB from accessing the file. 2 days of searching for a solution and I found nothing helpful. Does anyone know what am I missing. What is blocking the drop event?
Thanks for any help.
Code:Private Sub RichTextBox1_DragDrop(sender As Object, e As DragEventArgs) Handles RichTextBox1.DragDrop Dim filenames As String() = TryCast(e.Data.GetData(DataFormats.FileDrop), String()) Dim filetype As String = filenames(0).Substring(filenames(0).LastIndexOf("\") + 1) If filetype.IndexOf(".txt") <> -1 Then RichTextBox1.LoadFile(filenames(0), RichTextBoxStreamType.PlainText) ElseIf filetype.IndexOf(".rtf") <> -1 Then RichTextBox1.LoadFile(filenames(0), RichTextBoxStreamType.RichText) Else MessageBox.Show("Sorry, I cannot support this file type") End If End Sub Private Sub RichTextBox1_DragEnter(sender As Object, e As DragEventArgs) Handles RichTextBox1.DragEnter If (e.Data.GetDataPresent(DataFormats.Text)) Then e.Effect = DragDropEffects.Copy Else e.Effect = DragDropEffects.None End If End Sub




Reply With Quote
