C#的拖放问题
我想将网页上的一个链接拖进自己的winform窗口中,并获取此链接的标题和Url,请问各位大虾应该怎样用C#实现.
------解决方案--------------------http://www.21tx.com/dev/2005/05/04/13814.html
这个 是vb 实现的
------解决方案--------------------private void textBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
{
e.Effect= DragDropEffects.Link;
IDataObject data= e.Data;
object obj= data.GetData( "System.String ", true);
this.textBox1.Text= obj.ToString();
}
------解决方案--------------------如下的代码可以接收一个链接(Form1.AllowDrop=true才行,且一定要是链接以下代码才有效):
private void Form1_DragEnter(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(typeof(System.String)))
{
e.Effect = DragDropEffects.None;
return;
}
if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link)
{
e.Effect = DragDropEffects.Link;
}
}
private void Form1_DragOver(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent(typeof(System.String)))
{
e.Effect = DragDropEffects.None;
return;
}
if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link)
{
e.Effect = DragDropEffects.Link;
}
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(System.String)))
{
if (e.Effect == DragDropEffects.Link)
{
string item = (object)e.Data.GetData(typeof(System.String)) as string;
MessageBox.Show(item);
}
}
}