Results 1 to 4 of 4

Thread: [RESOLVED] [2.0] Drag and Drop from Internet Explorer

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2006
    Location
    City of Angles. Right Angles.
    Posts
    110

    [RESOLVED] [2.0] Drag and Drop from Internet Explorer

    Does anyone know how to drag and drop links from IE into a C# application? I am able to capture data from Mozilla Firefox without problems using this code:
    Code:
    private void Form1_DragDrop(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.Text))
        {
            // Firefox sends the url on the first line, the link text on the 2nd
            string url = e.Data.GetData(DataFormats.StringFormat).ToString();
            if (url.Contains("\n")) url = url.Substring(0, url.IndexOf("\n"));
            textBox1.Text = url;
        }
    }
    
    private void Form1_DragEnter(object sender, DragEventArgs e)
    {
        if (e.Data.GetDataPresent(DataFormats.Text))
        {
            e.Effect = DragDropEffects.Copy;
        }
        else
        {
            e.Effect = DragDropEffects.None;
        }
    }
    This same code does not work with Internet Explorer. I have tried IE6 and IE7 with the same results. I have done this before in VB, using the following code:
    Code:
    Private Sub lstMain_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstMain.DragOver
        If e.Data.GetData("System.String").ToString().StartsWith("http://") Then e.Effect = DragDropEffects.Link
    End Sub
    
    Private Sub lstMain_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lstMain.DragDrop
    
    Dim SiteName As String = "", SiteURL As String = "http://", SiteDescription As String = "", SiteFile As String
    Dim temp() As String, temp2 As String
    temp2 = e.Data.GetData("System.String")
    If temp2.Contains(vbLf) Then
        temp = Split(temp2, vbLf)
        SiteURL = temp(0)
        SiteName = temp(1)
    Else
        SiteURL = temp2
        SiteName = temp2.Substring(temp2.LastIndexOf("/") + 1)
    End If
    That code works fine in my VB application, but when checking for anything in the e.Data.GetDataPresent() method via the IE drop, nothing happens. I have tried all of the even remotely logical options in the DataFormats class, as well as passing in my own strings like "System.String" and "UniformResourceLocator". No matter what I try, dragging from IE doesn't trigger the code that changes the drag effect to Copy. If I put a break point on the code, it does enter the if statement, but the cursor never changes, and the DragDrop event never fires, not even the first if statement.

    Please help and thank you!

    PS, what happened to the [vbcode] tags? Clicking the VBCode button just asks me for highlighted text, which then turns red.
    Last edited by supertotallyawesome; Jun 28th, 2008 at 02:43 PM. Reason: Resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width