简体   繁体   English

在C#中使用WebBrowser控件的url drop

[英]Use url drop of WebBrowser control in C#

I would like to use the drop functionality of the WebBrowser control in C#. 我想在C#中使用WebBrowser控件的drop功能。 Unfortunately it doesn't work although I set the AllowWebBrowserDrop property to true. 不幸的是,虽然我将AllowWebBrowserDrop属性设置为true,但它不起作用。

For testing I wrote this little programm with just a textbox and a webbrowser control: 为了测试,我用一个文本框和一个webbrowser控件编写了这个小程序:

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 . DoDragDrop方法正确执行,但是当从WebControlTextBox删除字符串时,我从未看到MessageBox出现。 Since the WebControl doesn't offer the usual drag & drop events I'm lost. 由于WebControl不提供通常的拖放事件,我丢失了。

What do I have to do to make the url drop to the WebBrowser control work? 如何使url drop to WebBrowser控件工作?

Use the following approach to initiate FileDrop dragging: 使用以下方法启动FileDrop拖动:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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