WebBrowser Drag and Drop
-
Hi All, Has anybody been successful with drag and drop or pasting to a webbrowser control in VS 9.0 VB.net? All examples I have come across refer to ‘ExecWB’ which unfortunatly is not a member of System.windows.forms.webbrowser in VB.Net 9.0. There is a property ‘AllowWebBrowserDrop’ but how I trap the event when DragDrop, DragEnter, ect… events for the control don’t exist? I am not sure where to trap the drop event. I would gladly give you my firstborn for any relevant information on the subject. Thanks Stu
-
Hi All, Has anybody been successful with drag and drop or pasting to a webbrowser control in VS 9.0 VB.net? All examples I have come across refer to ‘ExecWB’ which unfortunatly is not a member of System.windows.forms.webbrowser in VB.Net 9.0. There is a property ‘AllowWebBrowserDrop’ but how I trap the event when DragDrop, DragEnter, ect… events for the control don’t exist? I am not sure where to trap the drop event. I would gladly give you my firstborn for any relevant information on the subject. Thanks Stu
Well... Nobody has answered my question so let me explain how I overcame the webbrowsers controls drag and drop issues. I created a transparent control (TCtl) that I placed over the webbrowser control I added handlers for dragenter and dragdrop for TCtl. I parsed the dropped html info to retrieve all of the images url's & then downloaded the images to a localdrive & replaced the href in the html to point to the local images. I then saved the html to a file. I could then load the file into the webbrowser control. Slicker than a rats ass if I may say so. Some of the code is shown below. For saving the images.... Source = web url, Dest = local drive.... Private Sub GetWebFile(ByVal strSource As String, ByVal strDest As String) Dim WebConnection As New WebClient() Try If File.Exists(strDest) Then File.Delete(strDest) WebConnection.DownloadFile(strSource, strDest) Catch ex As Exception MsgBox("Error retrieving web file", ex.Message) End Try End Sub For the drag and drop from a webpage (not complete).... Private Sub TCtlDragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) e.Effect = DragDropEffects.Copy If e.Data.GetDataPresent(DataFormats.Html) Then TCtlDropFormat = "HTML" ElseIf e.Data.GetDataPresent(DataFormats.FileDrop) Then TCtlDropFormat = "File" ElseIf e.Data.GetDataPresent(DataFormats.Bitmap) Then TCtlDropFormat = "Bitmap" ElseIf e.Data.GetDataPresent(DataFormats.Text) Then TCtlDropFormat = "Text" Else e.Effect = DragDropEffects.None End If End Sub Private Sub TCtlDragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Select Case TCtlDropFormat Case "HTML" Dim strData As String = e.Data.GetData(DataFormats.Html) DoHTMLDrop(strData) Case "File" Stop Case "Bitmap" Stop Case "Text" Stop End Select End Sub For the transparent control.... Public DWBSTCtl As New TransparentCtl DWBSTCtl.Left = 0 DWBSTCtl.Top = 0 DWBSTCtl.Width = wbData.Width - 20 DWBSTCtl.Height = wbData.Height DWBSTCtl.AllowDrop = True AddHandler DWBSTCtl.DragEnter, AddressOf TCtlDragEnter AddHandler DWBSTCtl.DragDrop, AddressO