簡體   English   中英

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

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

我想在C#中使用WebBrowser控件的drop功能。 不幸的是,雖然我將AllowWebBrowserDrop屬性設置為true,但它不起作用。

為了測試,我用一個文本框和一個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);
}

DoDragDrop方法正確執行,但是當從WebControlTextBox刪除字符串時,我從未看到MessageBox出現。 由於WebControl不提供通常的拖放事件,我丟失了。

如何使url drop to WebBrowser控件工作?

使用以下方法啟動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