http://community.csdn.net/Expert/TopicView.asp?id=5248113
这是前面一张帖子。
我终于知道了如何获取由浏览器拖放过来的URL地址。
之所以这个帖子拖了这么久,是因为我的程序里面对多种格式都进行了处理。
上一张帖子接收URL的类型判断为Text或UnicodeText或System.String
但是纯文本也是属于这些类型,但是纯文本好像不支持
e.Effect = DragDropEffects.Link
这样就造成了我也许可以采集文字,但是不能采集链接;
也许可以采集链接,但是不能采集文字。
当然,我所指的是在我用来接收拖放的浮动窗口上,鼠标拖放时能够显示允许拖放指针为标准的。
e.Effect = DragDropEffects.Copy
好像取不到Url……
请各位大大帮忙看看怎么处理这个DragEnter才能达到多种类型都能够顺利拖放进窗体的文本区里面。谢谢了!

解决方案 »

  1.   

    private void textBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
    {
    e.Effect = e.AllowedEffect;
    IDataObject data = e.Data;

    object obj = data.GetData("System.String", true);
    this.textBox1.Text = obj.ToString();
    }
      

  2.   

    这时已经被我搞得一团糟的代码
    加了很多测试语句进去了……
    对文本和链接始终无法正确识别…… private void TextContent_DragEnter(object sender, DragEventArgs e)
    {
    IDataObject data = e.Data;
    object objData = data.GetData( "UnicodeText" );
    if( objData != null )
    e.Effect = DragDropEffects.Link;
    if(e.Data.GetDataPresent(DataFormats.Html))
    {
    e.Effect = DragDropEffects.Copy;
    }
    if(e.Data.GetDataPresent(DataFormats.FileDrop))
    {
    e.Effect = DragDropEffects.Link;
    }
    if(e.Data.GetDataPresent(DataFormats.Text))
    {
    e.Effect = DragDropEffects.Copy;
    }
    else
    e.Effect=DragDropEffects.All;
    } private void TextContent_DragDrop(object sender, DragEventArgs e)
    {

    IDataObject data= e.Data;
    if(e.Data.GetDataPresent("System.String"))
    {
    object obj= data.GetData("System.String", true);
    TextContent.Text += obj.ToString();
    TextContent.Text+="\r\n";
    }
    //使用KeyState属性
    if((e.KeyState&(1<<3))!=0)
    {
    if(e.Data.GetDataPresent(DataFormats.Text))
    {
    e.Effect=DragDropEffects.Move;
    TextContent.Text+=e.Data.GetData(DataFormats.Text).ToString();
    TextContent.Text+="\r\n";
    }
    }
    else
    {
    //e.Effect=DragDropEffects.Move;
    //e.Effect=DragDropEffects.Copy;
    if(e.Data.GetDataPresent(DataFormats.Text))
    {
    if((e.AllowedEffect&DragDropEffects.Copy)!=0)
    TextContent.Text+=e.Data.GetData(DataFormats.Text).ToString();
    TextContent.Text+="\r\n";
    }
    }
    if(e.Data.GetDataPresent(DataFormats.FileDrop))
    {
    TextContent.Text+=((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
    TextContent.Text+="\r\n";
    }

    }
      

  3.   

    问题在于
    识别为文本时会设置e.Effect=DragDropEffects.Copy
    但是链接要用e.Effect=DragDropEffects.Link
    请问各位大大,这个条件怎么写才能够正确识别?
      

  4.   

    e.Effect= e.AllowedEffect;
    不能用吗?
      

  5.   

    额……
    解决了……
    感谢hatita(悠远的风景)
    我没看清楚……