简体   繁体   中英

Use url drop of WebBrowser control in C#

I would like to use the drop functionality of the WebBrowser control in C#. Unfortunately it doesn't work although I set the AllowWebBrowserDrop property to true.

For testing I wrote this little programm with just a textbox and a webbrowser control:

public Form1()
{
    InitializeComponent();
    webBrowser1.AllowWebBrowserDrop = true;
    textBox1.Text = "http://www.google.com";
}

private void textBox1_MouseMove(object sender, MouseEventArgs e)
{
    if (e.Button == System.Windows.Forms.MouseButtons.Left)
        DoDragDrop(textBox1.Text, DragDropEffects.Link);
}

private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
    MessageBox.Show(e.Url.AbsoluteUri);
}

The DoDragDrop method gets executed correctly, but I never see the MessageBox appearing when dropping the string from the TextBox over the WebControl . Since the WebControl doesn't offer the usual drag & drop events I'm lost.

What do I have to do to make the url drop to the WebBrowser control work?

Use the following approach to initiate FileDrop dragging:

DataObject dObj = new DataObject();
var paths = new System.Collections.Specialized.StringCollection();
paths.Add(textBox1.Text);
dObj.SetFileDropList(paths);
textBox1.DoDragDrop(dObj, DragDropEffects.Link);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM